1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

r20258: add functions to read and write asn1 encoded OID strings without leading tag

metze
(This used to be commit 576d4c54cc)
This commit is contained in:
Stefan Metzmacher 2006-12-19 19:25:49 +00:00 committed by Gerald (Jerry) Carter
parent 88ef467282
commit b55a68b368
2 changed files with 63 additions and 22 deletions

View File

@ -26,11 +26,11 @@
#include "core.h" #include "core.h"
#define GENSEC_OID_NTLMSSP "1 3 6 1 4 1 311 2 2 10" #define GENSEC_OID_NTLMSSP "1.3.6.1.4.1.311.2.2.10"
#define GENSEC_OID_SPNEGO "1 3 6 1 5 5 2" #define GENSEC_OID_SPNEGO "1.3.6.1.5.5.2"
#define GENSEC_OID_KERBEROS5 "1 2 840 113554 1 2 2" #define GENSEC_OID_KERBEROS5 "1.2.840.113554.1.2.2"
#define GENSEC_OID_KERBEROS5_OLD "1 2 840 48018 1 2 2" #define GENSEC_OID_KERBEROS5_OLD "1.2.840.48018.1.2.2"
#define GENSEC_OID_KERBEROS5_USER2USER "1 2 840 113554 1 2 2 3" #define GENSEC_OID_KERBEROS5_USER2USER "1.2.840.113554.1.2.2.3"
enum gensec_priority { enum gensec_priority {
GENSEC_SPNEGO = 90, GENSEC_SPNEGO = 90,

View File

@ -185,25 +185,37 @@ BOOL asn1_write_Integer(struct asn1_data *data, int i)
return asn1_pop_tag(data); return asn1_pop_tag(data);
} }
/* write an object ID to a ASN1 buffer */ BOOL asn1_write_OID_String(struct asn1_data *data, const char *OID)
BOOL asn1_write_OID(struct asn1_data *data, const char *OID)
{ {
uint_t v, v2; uint_t v, v2;
const char *p = (const char *)OID; const char *p = (const char *)OID;
char *newp; char *newp;
if (!asn1_push_tag(data, ASN1_OID)) v = strtoul(p, &newp, 10);
if (newp[0] != '.') {
data->has_error = True;
return False; return False;
v = strtol(p, &newp, 10); }
p = newp; p = newp + 1;
v2 = strtol(p, &newp, 10); v2 = strtoul(p, &newp, 10);
p = newp; if (newp[0] != '.') {
data->has_error = True;
return False;
}
p = newp + 1;
if (!asn1_write_uint8(data, 40*v + v2)) if (!asn1_write_uint8(data, 40*v + v2))
return False; return False;
while (*p) { while (*p) {
v = strtol(p, &newp, 10); v = strtoul(p, &newp, 10);
if (newp[0] == '.') {
p = newp + 1;
} else if (newp[0] == '\0') {
p = newp; p = newp;
} else {
data->has_error = True;
return False;
}
if (v >= (1<<28)) asn1_write_uint8(data, 0x80 | ((v>>28)&0xff)); if (v >= (1<<28)) asn1_write_uint8(data, 0x80 | ((v>>28)&0xff));
if (v >= (1<<21)) asn1_write_uint8(data, 0x80 | ((v>>21)&0xff)); if (v >= (1<<21)) asn1_write_uint8(data, 0x80 | ((v>>21)&0xff));
if (v >= (1<<14)) asn1_write_uint8(data, 0x80 | ((v>>14)&0xff)); if (v >= (1<<14)) asn1_write_uint8(data, 0x80 | ((v>>14)&0xff));
@ -211,6 +223,15 @@ BOOL asn1_write_OID(struct asn1_data *data, const char *OID)
if (!asn1_write_uint8(data, v&0x7f)) if (!asn1_write_uint8(data, v&0x7f))
return False; return False;
} }
return !data->has_error;
}
/* write an object ID to a ASN1 buffer */
BOOL asn1_write_OID(struct asn1_data *data, const char *OID)
{
if (!asn1_push_tag(data, ASN1_OID)) return False;
if (!asn1_write_OID_String(data, OID)) return False;
return asn1_pop_tag(data); return asn1_pop_tag(data);
} }
@ -447,16 +468,17 @@ int asn1_tag_remaining(struct asn1_data *data)
} }
/* read an object ID from a ASN1 buffer */ /* read an object ID from a ASN1 buffer */
BOOL asn1_read_OID(struct asn1_data *data, const char **OID) BOOL asn1_read_OID_String(struct asn1_data *data, const char **OID)
{ {
uint8_t b; uint8_t b;
char *tmp_oid = NULL; char *tmp_oid = NULL;
if (!asn1_start_tag(data, ASN1_OID)) return False; if (!asn1_read_uint8(data, &b)) return False;
asn1_read_uint8(data, &b);
tmp_oid = talloc_asprintf(NULL, "%u", b/40); tmp_oid = talloc_asprintf(NULL, "%u", b/40);
tmp_oid = talloc_asprintf_append(tmp_oid, " %u", b%40); if (!tmp_oid) goto nomem;
tmp_oid = talloc_asprintf_append(tmp_oid, ".%u", b%40);
if (!tmp_oid) goto nomem;
while (!data->has_error && asn1_tag_remaining(data) > 0) { while (!data->has_error && asn1_tag_remaining(data) > 0) {
uint_t v = 0; uint_t v = 0;
@ -464,15 +486,34 @@ BOOL asn1_read_OID(struct asn1_data *data, const char **OID)
asn1_read_uint8(data, &b); asn1_read_uint8(data, &b);
v = (v<<7) | (b&0x7f); v = (v<<7) | (b&0x7f);
} while (!data->has_error && (b & 0x80)); } while (!data->has_error && (b & 0x80));
tmp_oid = talloc_asprintf_append(tmp_oid, " %u", v); tmp_oid = talloc_asprintf_append(tmp_oid, ".%u", v);
if (!tmp_oid) goto nomem;
} }
asn1_end_tag(data); if (!data->has_error) {
*OID = talloc_strdup(NULL, tmp_oid); *OID = talloc_strdup(NULL, tmp_oid);
talloc_free(tmp_oid); if (!*OID) goto nomem;
}
return (*OID && !data->has_error); talloc_free(tmp_oid);
return !data->has_error;
nomem:
talloc_free(tmp_oid);
data->has_error = True;
return False;
}
/* read an object ID from a ASN1 buffer */
BOOL asn1_read_OID(struct asn1_data *data, const char **OID)
{
if (!asn1_start_tag(data, ASN1_OID)) return False;
if (!asn1_read_OID_String(data, OID)) return False;
if (!asn1_end_tag(data)) {
talloc_free(discard_const(*OID));
*OID = NULL;
return False;
}
return True;
} }
/* check that the next object ID is correct */ /* check that the next object ID is correct */