コード例 #1
0
ファイル: spnego_parse.c プロジェクト: AIdrifter/samba
static bool read_negTokenTarg(struct asn1_data *asn1, TALLOC_CTX *mem_ctx,
			      struct spnego_negTokenTarg *token)
{
	ZERO_STRUCTP(token);

	asn1_start_tag(asn1, ASN1_CONTEXT(1));
	asn1_start_tag(asn1, ASN1_SEQUENCE(0));

	while (!asn1->has_error && 0 < asn1_tag_remaining(asn1)) {
		uint8_t context;
		char *oid;
		if (!asn1_peek_uint8(asn1, &context)) {
			asn1->has_error = true;
			break;
		}

		switch (context) {
		case ASN1_CONTEXT(0):
			asn1_start_tag(asn1, ASN1_CONTEXT(0));
			asn1_start_tag(asn1, ASN1_ENUMERATED);
			asn1_read_uint8(asn1, &token->negResult);
			asn1_end_tag(asn1);
			asn1_end_tag(asn1);
			break;
		case ASN1_CONTEXT(1):
			asn1_start_tag(asn1, ASN1_CONTEXT(1));
			asn1_read_OID(asn1, mem_ctx, &oid);
			token->supportedMech = oid;
			asn1_end_tag(asn1);
			break;
		case ASN1_CONTEXT(2):
			asn1_start_tag(asn1, ASN1_CONTEXT(2));
			asn1_read_OctetString(asn1, mem_ctx, &token->responseToken);
			asn1_end_tag(asn1);
			break;
		case ASN1_CONTEXT(3):
			asn1_start_tag(asn1, ASN1_CONTEXT(3));
			asn1_read_OctetString(asn1, mem_ctx, &token->mechListMIC);
			asn1_end_tag(asn1);
			break;
		default:
			asn1->has_error = true;
			break;
		}
	}

	asn1_end_tag(asn1);
	asn1_end_tag(asn1);

	return !asn1->has_error;
}
コード例 #2
0
ファイル: spnego.c プロジェクト: jameshilliard/WECB-BH-GPL
static bool read_negTokenTarg(ASN1_DATA *asn1, negTokenTarg_t *token)
{
	ZERO_STRUCTP(token);

	asn1_start_tag(asn1, ASN1_CONTEXT(1));
	asn1_start_tag(asn1, ASN1_SEQUENCE(0));

	while (!asn1->has_error && 0 < asn1_tag_remaining(asn1)) {
		switch (asn1->data[asn1->ofs]) {
		case ASN1_CONTEXT(0):
			asn1_start_tag(asn1, ASN1_CONTEXT(0));
			asn1_start_tag(asn1, ASN1_ENUMERATED);
			asn1_read_uint8(asn1, &token->negResult);
			asn1_end_tag(asn1);
			asn1_end_tag(asn1);
			break;
		case ASN1_CONTEXT(1):
			asn1_start_tag(asn1, ASN1_CONTEXT(1));
			asn1_read_OID(asn1, &token->supportedMech);
			asn1_end_tag(asn1);
			break;
		case ASN1_CONTEXT(2):
			asn1_start_tag(asn1, ASN1_CONTEXT(2));
			asn1_read_OctetString(asn1, &token->responseToken);
			asn1_end_tag(asn1);
			break;
		case ASN1_CONTEXT(3):
			asn1_start_tag(asn1, ASN1_CONTEXT(3));
			asn1_read_OctetString(asn1, &token->mechListMIC);
			asn1_end_tag(asn1);
			break;
		default:
			asn1->has_error = True;
			break;
		}
	}

	asn1_end_tag(asn1);
	asn1_end_tag(asn1);

	return !asn1->has_error;
}
コード例 #3
0
ファイル: clispnego.c プロジェクト: berserker/android_samba
/*
  parse a negTokenInit packet giving a GUID, a list of supported
  OIDs (the mechanisms) and a principal name string
*/
bool spnego_parse_negTokenInit(TALLOC_CTX *ctx,
                               DATA_BLOB blob,
                               char *OIDs[ASN1_MAX_OIDS],
                               char **principal,
                               DATA_BLOB *secblob)
{
    int i;
    bool ret;
    ASN1_DATA *data;

    data = asn1_init(talloc_tos());
    if (data == NULL) {
        return false;
    }

    asn1_load(data, blob);

    asn1_start_tag(data,ASN1_APPLICATION(0));

    asn1_check_OID(data,OID_SPNEGO);

    /* negTokenInit  [0]  NegTokenInit */
    asn1_start_tag(data,ASN1_CONTEXT(0));
    asn1_start_tag(data,ASN1_SEQUENCE(0));

    /* mechTypes [0] MechTypeList  OPTIONAL */

    /* Not really optional, we depend on this to decide
     * what mechanisms we have to work with. */

    asn1_start_tag(data,ASN1_CONTEXT(0));
    asn1_start_tag(data,ASN1_SEQUENCE(0));
    for (i=0; asn1_tag_remaining(data) > 0 && i < ASN1_MAX_OIDS-1; i++) {
        asn1_read_OID(data,ctx, &OIDs[i]);
        if (data->has_error) {
            break;
        }
    }
    OIDs[i] = NULL;
    asn1_end_tag(data);
    asn1_end_tag(data);

    if (principal) {
        *principal = NULL;
    }
    if (secblob) {
        *secblob = data_blob_null;
    }

    /*
      Win7 + Live Sign-in Assistant attaches a mechToken
      ASN1_CONTEXT(2) to the negTokenInit packet
      which breaks our negotiation if we just assume
      the next tag is ASN1_CONTEXT(3).
    */

    if (asn1_peek_tag(data, ASN1_CONTEXT(1))) {
        uint8 flags;

        /* reqFlags [1] ContextFlags  OPTIONAL */
        asn1_start_tag(data, ASN1_CONTEXT(1));
        asn1_start_tag(data, ASN1_BIT_STRING);
        while (asn1_tag_remaining(data) > 0) {
            asn1_read_uint8(data, &flags);
        }
        asn1_end_tag(data);
        asn1_end_tag(data);
    }

    if (asn1_peek_tag(data, ASN1_CONTEXT(2))) {
        DATA_BLOB sblob = data_blob_null;
        /* mechToken [2] OCTET STRING  OPTIONAL */
        asn1_start_tag(data, ASN1_CONTEXT(2));
        asn1_read_OctetString(data, ctx, &sblob);
        asn1_end_tag(data);
        if (secblob) {
            *secblob = sblob;
        } else {
            data_blob_free(&sblob);
        }
    }

    if (asn1_peek_tag(data, ASN1_CONTEXT(3))) {
        char *princ = NULL;
        /* mechListMIC [3] OCTET STRING  OPTIONAL */
        asn1_start_tag(data, ASN1_CONTEXT(3));
        asn1_start_tag(data, ASN1_SEQUENCE(0));
        asn1_start_tag(data, ASN1_CONTEXT(0));
        asn1_read_GeneralString(data, ctx, &princ);
        asn1_end_tag(data);
        asn1_end_tag(data);
        asn1_end_tag(data);
        if (principal) {
            *principal = princ;
        } else {
            TALLOC_FREE(princ);
        }
    }

    asn1_end_tag(data);
    asn1_end_tag(data);

    asn1_end_tag(data);

    ret = !data->has_error;
    if (data->has_error) {
        int j;
        if (principal) {
            TALLOC_FREE(*principal);
        }
        if (secblob) {
            data_blob_free(secblob);
        }
        for(j = 0; j < i && j < ASN1_MAX_OIDS-1; j++) {
            TALLOC_FREE(OIDs[j]);
        }
    }

    asn1_free(data);
    return ret;
}