OLD | NEW |
1 /* alg1485.c - implementation of RFCs 1485, 1779 and 2253. | 1 /* alg1485.c - implementation of RFCs 1485, 1779 and 2253. |
2 * | 2 * |
3 * This Source Code Form is subject to the terms of the Mozilla Public | 3 * This Source Code Form is subject to the terms of the Mozilla Public |
4 * License, v. 2.0. If a copy of the MPL was not distributed with this | 4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | 6 |
7 #include "prprf.h" | 7 #include "prprf.h" |
8 #include "cert.h" | 8 #include "cert.h" |
9 #include "certi.h" | 9 #include "certi.h" |
10 #include "xconst.h" | 10 #include "xconst.h" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 } | 356 } |
357 | 357 |
358 /* Parses one AVA, starting at *pbp. Stops at endptr. | 358 /* Parses one AVA, starting at *pbp. Stops at endptr. |
359 * Advances *pbp past parsed AVA and trailing separator (if present). | 359 * Advances *pbp past parsed AVA and trailing separator (if present). |
360 * On any error, returns NULL and *pbp is undefined. | 360 * On any error, returns NULL and *pbp is undefined. |
361 * On success, returns CERTAVA allocated from arena, and (*pbp)[-1] was | 361 * On success, returns CERTAVA allocated from arena, and (*pbp)[-1] was |
362 * the last character parsed. *pbp is either equal to endptr or | 362 * the last character parsed. *pbp is either equal to endptr or |
363 * points to first character after separator. | 363 * points to first character after separator. |
364 */ | 364 */ |
365 static CERTAVA * | 365 static CERTAVA * |
366 ParseRFC1485AVA(PRArenaPool *arena, const char **pbp, const char *endptr) | 366 ParseRFC1485AVA(PLArenaPool *arena, const char **pbp, const char *endptr) |
367 { | 367 { |
368 CERTAVA *a; | 368 CERTAVA *a; |
369 const NameToKind *n2k; | 369 const NameToKind *n2k; |
370 const char *bp; | 370 const char *bp; |
371 int vt = -1; | 371 int vt = -1; |
372 int valLen; | 372 int valLen; |
373 SECOidTag kind = SEC_OID_UNKNOWN; | 373 SECOidTag kind = SEC_OID_UNKNOWN; |
374 SECStatus rv = SECFailure; | 374 SECStatus rv = SECFailure; |
375 SECItem derOid = { 0, NULL, 0 }; | 375 SECItem derOid = { 0, NULL, 0 }; |
376 SECItem derVal = { 0, NULL, 0}; | 376 SECItem derVal = { 0, NULL, 0}; |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 } | 1132 } |
1133 | 1133 |
1134 /* | 1134 /* |
1135 * Return the string representation of a DER encoded distinguished name | 1135 * Return the string representation of a DER encoded distinguished name |
1136 * "dername" - The DER encoded name to convert | 1136 * "dername" - The DER encoded name to convert |
1137 */ | 1137 */ |
1138 char * | 1138 char * |
1139 CERT_DerNameToAscii(SECItem *dername) | 1139 CERT_DerNameToAscii(SECItem *dername) |
1140 { | 1140 { |
1141 int rv; | 1141 int rv; |
1142 PRArenaPool *arena = NULL; | 1142 PLArenaPool *arena = NULL; |
1143 CERTName name; | 1143 CERTName name; |
1144 char *retstr = NULL; | 1144 char *retstr = NULL; |
1145 | 1145 |
1146 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); | 1146 arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
1147 | 1147 |
1148 if ( arena == NULL) { | 1148 if ( arena == NULL) { |
1149 goto loser; | 1149 goto loser; |
1150 } | 1150 } |
1151 | 1151 |
1152 rv = SEC_QuickDERDecodeItem(arena, &name, CERT_NameTemplate, dername); | 1152 rv = SEC_QuickDERDecodeItem(arena, &name, CERT_NameTemplate, dername); |
1153 | 1153 |
1154 if ( rv != SECSuccess ) { | 1154 if ( rv != SECSuccess ) { |
1155 goto loser; | 1155 goto loser; |
1156 } | 1156 } |
1157 | 1157 |
1158 retstr = CERT_NameToAscii(&name); | 1158 retstr = CERT_NameToAscii(&name); |
1159 | 1159 |
1160 loser: | 1160 loser: |
1161 if ( arena != NULL ) { | 1161 if ( arena != NULL ) { |
1162 PORT_FreeArena(arena, PR_FALSE); | 1162 PORT_FreeArena(arena, PR_FALSE); |
1163 } | 1163 } |
1164 | 1164 |
1165 return(retstr); | 1165 return(retstr); |
1166 } | 1166 } |
1167 | 1167 |
1168 static char * | 1168 static char * |
1169 avaToString(PRArenaPool *arena, CERTAVA *ava) | 1169 avaToString(PLArenaPool *arena, CERTAVA *ava) |
1170 { | 1170 { |
1171 char * buf = NULL; | 1171 char * buf = NULL; |
1172 SECItem* avaValue; | 1172 SECItem* avaValue; |
1173 int valueLen; | 1173 int valueLen; |
1174 | 1174 |
1175 avaValue = CERT_DecodeAVAValue(&ava->value); | 1175 avaValue = CERT_DecodeAVAValue(&ava->value); |
1176 if(!avaValue) { | 1176 if(!avaValue) { |
1177 return buf; | 1177 return buf; |
1178 } | 1178 } |
1179 valueLen = cert_RFC1485_GetRequiredLen((char *)avaValue->data, | 1179 valueLen = cert_RFC1485_GetRequiredLen((char *)avaValue->data, |
(...skipping 13 matching lines...) Expand all Loading... |
1193 } | 1193 } |
1194 } | 1194 } |
1195 SECITEM_FreeItem(avaValue, PR_TRUE); | 1195 SECITEM_FreeItem(avaValue, PR_TRUE); |
1196 return buf; | 1196 return buf; |
1197 } | 1197 } |
1198 | 1198 |
1199 /* RDNs are sorted from most general to most specific. | 1199 /* RDNs are sorted from most general to most specific. |
1200 * This code returns the FIRST one found, the most general one found. | 1200 * This code returns the FIRST one found, the most general one found. |
1201 */ | 1201 */ |
1202 static char * | 1202 static char * |
1203 CERT_GetNameElement(PRArenaPool *arena, const CERTName *name, int wantedTag) | 1203 CERT_GetNameElement(PLArenaPool *arena, const CERTName *name, int wantedTag) |
1204 { | 1204 { |
1205 CERTRDN** rdns = name->rdns; | 1205 CERTRDN** rdns = name->rdns; |
1206 CERTRDN* rdn; | 1206 CERTRDN* rdn; |
1207 CERTAVA* ava = NULL; | 1207 CERTAVA* ava = NULL; |
1208 | 1208 |
1209 while (rdns && (rdn = *rdns++) != 0) { | 1209 while (rdns && (rdn = *rdns++) != 0) { |
1210 CERTAVA** avas = rdn->avas; | 1210 CERTAVA** avas = rdn->avas; |
1211 while (avas && (ava = *avas++) != 0) { | 1211 while (avas && (ava = *avas++) != 0) { |
1212 int tag = CERT_GetAVATag(ava); | 1212 int tag = CERT_GetAVATag(ava); |
1213 if ( tag == wantedTag ) { | 1213 if ( tag == wantedTag ) { |
1214 avas = NULL; | 1214 avas = NULL; |
1215 rdns = NULL; /* break out of all loops */ | 1215 rdns = NULL; /* break out of all loops */ |
1216 } | 1216 } |
1217 } | 1217 } |
1218 } | 1218 } |
1219 return ava ? avaToString(arena, ava) : NULL; | 1219 return ava ? avaToString(arena, ava) : NULL; |
1220 } | 1220 } |
1221 | 1221 |
1222 /* RDNs are sorted from most general to most specific. | 1222 /* RDNs are sorted from most general to most specific. |
1223 * This code returns the LAST one found, the most specific one found. | 1223 * This code returns the LAST one found, the most specific one found. |
1224 * This is particularly appropriate for Common Name. See RFC 2818. | 1224 * This is particularly appropriate for Common Name. See RFC 2818. |
1225 */ | 1225 */ |
1226 static char * | 1226 static char * |
1227 CERT_GetLastNameElement(PRArenaPool *arena, const CERTName *name, int wantedTag) | 1227 CERT_GetLastNameElement(PLArenaPool *arena, const CERTName *name, int wantedTag) |
1228 { | 1228 { |
1229 CERTRDN** rdns = name->rdns; | 1229 CERTRDN** rdns = name->rdns; |
1230 CERTRDN* rdn; | 1230 CERTRDN* rdn; |
1231 CERTAVA* lastAva = NULL; | 1231 CERTAVA* lastAva = NULL; |
1232 | 1232 |
1233 while (rdns && (rdn = *rdns++) != 0) { | 1233 while (rdns && (rdn = *rdns++) != 0) { |
1234 CERTAVA** avas = rdn->avas; | 1234 CERTAVA** avas = rdn->avas; |
1235 CERTAVA* ava; | 1235 CERTAVA* ava; |
1236 while (avas && (ava = *avas++) != 0) { | 1236 while (avas && (ava = *avas++) != 0) { |
1237 int tag = CERT_GetAVATag(ava); | 1237 int tag = CERT_GetAVATag(ava); |
1238 if ( tag == wantedTag ) { | 1238 if ( tag == wantedTag ) { |
1239 lastAva = ava; | 1239 lastAva = ava; |
1240 } | 1240 } |
1241 } | 1241 } |
1242 } | 1242 } |
1243 return lastAva ? avaToString(arena, lastAva) : NULL; | 1243 return lastAva ? avaToString(arena, lastAva) : NULL; |
1244 } | 1244 } |
1245 | 1245 |
1246 char * | 1246 char * |
1247 CERT_GetCertificateEmailAddress(CERTCertificate *cert) | 1247 CERT_GetCertificateEmailAddress(CERTCertificate *cert) |
1248 { | 1248 { |
1249 char *rawEmailAddr = NULL; | 1249 char *rawEmailAddr = NULL; |
1250 SECItem subAltName; | 1250 SECItem subAltName; |
1251 SECStatus rv; | 1251 SECStatus rv; |
1252 CERTGeneralName *nameList = NULL; | 1252 CERTGeneralName *nameList = NULL; |
1253 CERTGeneralName *current; | 1253 CERTGeneralName *current; |
1254 PRArenaPool *arena = NULL; | 1254 PLArenaPool *arena = NULL; |
1255 int i; | 1255 int i; |
1256 | 1256 |
1257 subAltName.data = NULL; | 1257 subAltName.data = NULL; |
1258 | 1258 |
1259 rawEmailAddr = CERT_GetNameElement(cert->arena, &(cert->subject), | 1259 rawEmailAddr = CERT_GetNameElement(cert->arena, &(cert->subject), |
1260 SEC_OID_PKCS9_EMAIL_ADDRESS); | 1260 SEC_OID_PKCS9_EMAIL_ADDRESS); |
1261 if ( rawEmailAddr == NULL ) { | 1261 if ( rawEmailAddr == NULL ) { |
1262 rawEmailAddr = CERT_GetNameElement(cert->arena, &(cert->subject), | 1262 rawEmailAddr = CERT_GetNameElement(cert->arena, &(cert->subject), |
1263 SEC_OID_RFC1274_MAIL); | 1263 SEC_OID_RFC1274_MAIL); |
1264 } | 1264 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1376 /* Returns a pointer to an environment-like string, a series of | 1376 /* Returns a pointer to an environment-like string, a series of |
1377 ** null-terminated strings, terminated by a zero-length string. | 1377 ** null-terminated strings, terminated by a zero-length string. |
1378 ** This function is intended to be internal to NSS. | 1378 ** This function is intended to be internal to NSS. |
1379 */ | 1379 */ |
1380 char * | 1380 char * |
1381 cert_GetCertificateEmailAddresses(CERTCertificate *cert) | 1381 cert_GetCertificateEmailAddresses(CERTCertificate *cert) |
1382 { | 1382 { |
1383 char * rawEmailAddr = NULL; | 1383 char * rawEmailAddr = NULL; |
1384 char * addrBuf = NULL; | 1384 char * addrBuf = NULL; |
1385 char * pBuf = NULL; | 1385 char * pBuf = NULL; |
1386 PRArenaPool * tmpArena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); | 1386 PLArenaPool * tmpArena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
1387 PRUint32 maxLen = 0; | 1387 PRUint32 maxLen = 0; |
1388 PRInt32 finalLen = 0; | 1388 PRInt32 finalLen = 0; |
1389 SECStatus rv; | 1389 SECStatus rv; |
1390 SECItem subAltName; | 1390 SECItem subAltName; |
1391 | 1391 |
1392 if (!tmpArena) | 1392 if (!tmpArena) |
1393 return addrBuf; | 1393 return addrBuf; |
1394 | 1394 |
1395 subAltName.data = NULL; | 1395 subAltName.data = NULL; |
1396 maxLen = cert->derCert.len; | 1396 maxLen = cert->derCert.len; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1551 { | 1551 { |
1552 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_DN_QUALIFIER)); | 1552 return(CERT_GetNameElement(NULL, name, SEC_OID_AVA_DN_QUALIFIER)); |
1553 } | 1553 } |
1554 | 1554 |
1555 char * | 1555 char * |
1556 CERT_GetCertUid(const CERTName *name) | 1556 CERT_GetCertUid(const CERTName *name) |
1557 { | 1557 { |
1558 return(CERT_GetNameElement(NULL, name, SEC_OID_RFC1274_UID)); | 1558 return(CERT_GetNameElement(NULL, name, SEC_OID_RFC1274_UID)); |
1559 } | 1559 } |
1560 | 1560 |
OLD | NEW |