openssl.txt 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. This is some preliminary documentation for OpenSSL.
  2. Contents:
  3. OpenSSL X509V3 extension configuration
  4. X509V3 Extension code: programmers guide
  5. PKCS#12 Library
  6. ==============================================================================
  7. OpenSSL X509V3 extension configuration
  8. ==============================================================================
  9. OpenSSL X509V3 extension configuration: preliminary documentation.
  10. INTRODUCTION.
  11. For OpenSSL 0.9.2 the extension code has be considerably enhanced. It is now
  12. possible to add and print out common X509 V3 certificate and CRL extensions.
  13. BEGINNERS NOTE
  14. For most simple applications you don't need to know too much about extensions:
  15. the default openssl.cnf values will usually do sensible things.
  16. If you want to know more you can initially quickly look through the sections
  17. describing how the standard OpenSSL utilities display and add extensions and
  18. then the list of supported extensions.
  19. For more technical information about the meaning of extensions see:
  20. http://www.imc.org/ietf-pkix/
  21. http://home.netscape.com/eng/security/certs.html
  22. PRINTING EXTENSIONS.
  23. Extension values are automatically printed out for supported extensions.
  24. openssl x509 -in cert.pem -text
  25. openssl crl -in crl.pem -text
  26. will give information in the extension printout, for example:
  27. X509v3 extensions:
  28. X509v3 Basic Constraints:
  29. CA:TRUE
  30. X509v3 Subject Key Identifier:
  31. 73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15
  32. X509v3 Authority Key Identifier:
  33. keyid:73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15, DirName:/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/Email=email@1.address/Email=email@2.address, serial:00
  34. X509v3 Key Usage:
  35. Certificate Sign, CRL Sign
  36. X509v3 Subject Alternative Name:
  37. email:email@1.address, email:email@2.address
  38. CONFIGURATION FILES.
  39. The OpenSSL utilities 'ca' and 'req' can now have extension sections listing
  40. which certificate extensions to include. In each case a line:
  41. x509_extensions = extension_section
  42. indicates which section contains the extensions. In the case of 'req' the
  43. extension section is used when the -x509 option is present to create a
  44. self signed root certificate.
  45. The 'x509' utility also supports extensions when it signs a certificate.
  46. The -extfile option is used to set the configuration file containing the
  47. extensions. In this case a line with:
  48. extensions = extension_section
  49. in the nameless (default) section is used. If no such line is included then
  50. it uses the default section.
  51. You can also add extensions to CRLs: a line
  52. crl_extensions = crl_extension_section
  53. will include extensions when the -gencrl option is used with the 'ca' utility.
  54. You can add any extension to a CRL but of the supported extensions only
  55. issuerAltName and authorityKeyIdentifier make any real sense. Note: these are
  56. CRL extensions NOT CRL *entry* extensions which cannot currently be generated.
  57. CRL entry extensions can be displayed.
  58. NB. At this time Netscape Communicator rejects V2 CRLs: to get an old V1 CRL
  59. you should not include a crl_extensions line in the configuration file.
  60. As with all configuration files you can use the inbuilt environment expansion
  61. to allow the values to be passed in the environment. Therefore if you have
  62. several extension sections used for different purposes you can have a line:
  63. x509_extensions = $ENV::ENV_EXT
  64. and set the ENV_EXT environment variable before calling the relevant utility.
  65. EXTENSION SYNTAX.
  66. Extensions have the basic form:
  67. extension_name=[critical,] extension_options
  68. the use of the critical option makes the extension critical. Extreme caution
  69. should be made when using the critical flag. If an extension is marked
  70. as critical then any client that does not understand the extension should
  71. reject it as invalid. Some broken software will reject certificates which
  72. have *any* critical extensions (these violates PKIX but we have to live
  73. with it).
  74. There are three main types of extension: string extensions, multi-valued
  75. extensions, and raw extensions.
  76. String extensions simply have a string which contains either the value itself
  77. or how it is obtained.
  78. For example:
  79. nsComment="This is a Comment"
  80. Multi-valued extensions have a short form and a long form. The short form
  81. is a list of names and values:
  82. basicConstraints=critical,CA:true,pathlen:1
  83. The long form allows the values to be placed in a separate section:
  84. basicConstraints=critical,@bs_section
  85. [bs_section]
  86. CA=true
  87. pathlen=1
  88. Both forms are equivalent. However it should be noted that in some cases the
  89. same name can appear multiple times, for example,
  90. subjectAltName=email:steve@here,email:steve@there
  91. in this case an equivalent long form is:
  92. subjectAltName=@alt_section
  93. [alt_section]
  94. email.1=steve@here
  95. email.2=steve@there
  96. This is because the configuration file code cannot handle the same name
  97. occurring twice in the same section.
  98. The syntax of raw extensions is governed by the extension code: it can
  99. for example contain data in multiple sections. The correct syntax to
  100. use is defined by the extension code itself: check out the certificate
  101. policies extension for an example.
  102. In addition it is also possible to use the word DER to include arbitrary
  103. data in any extension.
  104. 1.2.3.4=critical,DER:01:02:03:04
  105. 1.2.3.4=DER:01020304
  106. The value following DER is a hex dump of the DER encoding of the extension
  107. Any extension can be placed in this form to override the default behaviour.
  108. For example:
  109. basicConstraints=critical,DER:00:01:02:03
  110. WARNING: DER should be used with caution. It is possible to create totally
  111. invalid extensions unless care is taken.
  112. CURRENTLY SUPPORTED EXTENSIONS.
  113. If you aren't sure about extensions then they can be largely ignored: its only
  114. when you want to do things like restrict certificate usage when you need to
  115. worry about them.
  116. The only extension that a beginner might want to look at is Basic Constraints.
  117. If in addition you want to try Netscape object signing the you should also
  118. look at Netscape Certificate Type.
  119. Literal String extensions.
  120. In each case the 'value' of the extension is placed directly in the
  121. extension. Currently supported extensions in this category are: nsBaseUrl,
  122. nsRevocationUrl, nsCaRevocationUrl, nsRenewalUrl, nsCaPolicyUrl,
  123. nsSslServerName and nsComment.
  124. For example:
  125. nsComment="This is a test comment"
  126. Bit Strings.
  127. Bit string extensions just consist of a list of supported bits, currently
  128. two extensions are in this category: PKIX keyUsage and the Netscape specific
  129. nsCertType.
  130. nsCertType (netscape certificate type) takes the flags: client, server, email,
  131. objsign, reserved, sslCA, emailCA, objCA.
  132. keyUsage (PKIX key usage) takes the flags: digitalSignature, nonRepudiation,
  133. keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, cRLSign,
  134. encipherOnly, decipherOnly.
  135. For example:
  136. nsCertType=server
  137. keyUsage=digitalSignature, nonRepudiation
  138. Hints on Netscape Certificate Type.
  139. Other than Basic Constraints this is the only extension a beginner might
  140. want to use, if you want to try Netscape object signing, otherwise it can
  141. be ignored.
  142. If you want a certificate that can be used just for object signing then:
  143. nsCertType=objsign
  144. will do the job. If you want to use it as a normal end user and server
  145. certificate as well then
  146. nsCertType=objsign,email,server
  147. is more appropriate. You cannot use a self signed certificate for object
  148. signing (well Netscape signtool can but it cheats!) so you need to create
  149. a CA certificate and sign an end user certificate with it.
  150. Side note: If you want to conform to the Netscape specifications then you
  151. should really also set:
  152. nsCertType=objCA
  153. in the *CA* certificate for just an object signing CA and
  154. nsCertType=objCA,emailCA,sslCA
  155. for everything. Current Netscape software doesn't enforce this so it can
  156. be omitted.
  157. Basic Constraints.
  158. This is generally the only extension you need to worry about for simple
  159. applications. If you want your certificate to be usable as a CA certificate
  160. (in addition to an end user certificate) then you set this to:
  161. basicConstraints=CA:TRUE
  162. if you want to be certain the certificate cannot be used as a CA then do:
  163. basicConstraints=CA:FALSE
  164. The rest of this section describes more advanced usage.
  165. Basic constraints is a multi-valued extension that supports a CA and an
  166. optional pathlen option. The CA option takes the values true and false and
  167. pathlen takes an integer. Note if the CA option is false the pathlen option
  168. should be omitted.
  169. The pathlen parameter indicates the maximum number of CAs that can appear
  170. below this one in a chain. So if you have a CA with a pathlen of zero it can
  171. only be used to sign end user certificates and not further CAs. This all
  172. assumes that the software correctly interprets this extension of course.
  173. Examples:
  174. basicConstraints=CA:TRUE
  175. basicConstraints=critical,CA:TRUE, pathlen:0
  176. NOTE: for a CA to be considered valid it must have the CA option set to
  177. TRUE. An end user certificate MUST NOT have the CA value set to true.
  178. According to PKIX recommendations it should exclude the extension entirely,
  179. however some software may require CA set to FALSE for end entity certificates.
  180. Extended Key Usage.
  181. This extensions consists of a list of usages.
  182. These can either be object short names of the dotted numerical form of OIDs.
  183. While any OID can be used only certain values make sense. In particular the
  184. following PKIX, NS and MS values are meaningful:
  185. Value Meaning
  186. ----- -------
  187. serverAuth SSL/TLS Web Server Authentication.
  188. clientAuth SSL/TLS Web Client Authentication.
  189. codeSigning Code signing.
  190. emailProtection E-mail Protection (S/MIME).
  191. timeStamping Trusted Timestamping
  192. msCodeInd Microsoft Individual Code Signing (authenticode)
  193. msCodeCom Microsoft Commercial Code Signing (authenticode)
  194. msCTLSign Microsoft Trust List Signing
  195. msSGC Microsoft Server Gated Crypto
  196. msEFS Microsoft Encrypted File System
  197. nsSGC Netscape Server Gated Crypto
  198. For example, under IE5 a CA can be used for any purpose: by including a list
  199. of the above usages the CA can be restricted to only authorised uses.
  200. Note: software packages may place additional interpretations on certificate
  201. use, in particular some usages may only work for selected CAs. Don't for example
  202. expect just including msSGC or nsSGC will automatically mean that a certificate
  203. can be used for SGC ("step up" encryption) otherwise anyone could use it.
  204. Examples:
  205. extendedKeyUsage=critical,codeSigning,1.2.3.4
  206. extendedKeyUsage=nsSGC,msSGC
  207. Subject Key Identifier.
  208. This is really a string extension and can take two possible values. Either
  209. a hex string giving details of the extension value to include or the word
  210. 'hash' which then automatically follow PKIX guidelines in selecting and
  211. appropriate key identifier. The use of the hex string is strongly discouraged.
  212. Example: subjectKeyIdentifier=hash
  213. Authority Key Identifier.
  214. The authority key identifier extension permits two options. keyid and issuer:
  215. both can take the optional value "always".
  216. If the keyid option is present an attempt is made to copy the subject key
  217. identifier from the parent certificate. If the value "always" is present
  218. then an error is returned if the option fails.
  219. The issuer option copies the issuer and serial number from the issuer
  220. certificate. Normally this will only be done if the keyid option fails or
  221. is not included: the "always" flag will always include the value.
  222. Subject Alternative Name.
  223. The subject alternative name extension allows various literal values to be
  224. included in the configuration file. These include "email" (an email address)
  225. "URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a
  226. registered ID: OBJECT IDENTIFIER) and IP (and IP address).
  227. Also the email option include a special 'copy' value. This will automatically
  228. include and email addresses contained in the certificate subject name in
  229. the extension.
  230. Examples:
  231. subjectAltName=email:copy,email:my@other.address,URI:http://my.url.here/
  232. subjectAltName=email:my@other.address,RID:1.2.3.4
  233. Issuer Alternative Name.
  234. The issuer alternative name option supports all the literal options of
  235. subject alternative name. It does *not* support the email:copy option because
  236. that would not make sense. It does support an additional issuer:copy option
  237. that will copy all the subject alternative name values from the issuer
  238. certificate (if possible).
  239. Example:
  240. issuserAltName = issuer:copy
  241. Authority Info Access.
  242. The authority information access extension gives details about how to access
  243. certain information relating to the CA. Its syntax is accessOID;location
  244. where 'location' has the same syntax as subject alternative name (except
  245. that email:copy is not supported). accessOID can be any valid OID but only
  246. certain values are meaningful for example OCSP and caIssuers. OCSP gives the
  247. location of an OCSP responder: this is used by Netscape PSM and other software.
  248. Example:
  249. authorityInfoAccess = OCSP;URI:http://ocsp.my.host/
  250. authorityInfoAccess = caIssuers;URI:http://my.ca/ca.html
  251. CRL distribution points.
  252. This is a multi-valued extension that supports all the literal options of
  253. subject alternative name. Of the few software packages that currently interpret
  254. this extension most only interpret the URI option.
  255. Currently each option will set a new DistributionPoint with the fullName
  256. field set to the given value.
  257. Other fields like cRLissuer and reasons cannot currently be set or displayed:
  258. at this time no examples were available that used these fields.
  259. If you see this extension with <UNSUPPORTED> when you attempt to print it out
  260. or it doesn't appear to display correctly then let me know, including the
  261. certificate (mail me at steve@openssl.org) .
  262. Examples:
  263. crlDistributionPoints=URI:http://www.myhost.com/myca.crl
  264. crlDistributionPoints=URI:http://www.my.com/my.crl,URI:http://www.oth.com/my.crl
  265. Certificate Policies.
  266. This is a RAW extension. It attempts to display the contents of this extension:
  267. unfortunately this extension is often improperly encoded.
  268. The certificate policies extension will rarely be used in practice: few
  269. software packages interpret it correctly or at all. IE5 does partially
  270. support this extension: but it needs the 'ia5org' option because it will
  271. only correctly support a broken encoding. Of the options below only the
  272. policy OID, explicitText and CPS options are displayed with IE5.
  273. All the fields of this extension can be set by using the appropriate syntax.
  274. If you follow the PKIX recommendations of not including any qualifiers and just
  275. using only one OID then you just include the value of that OID. Multiple OIDs
  276. can be set separated by commas, for example:
  277. certificatePolicies= 1.2.4.5, 1.1.3.4
  278. If you wish to include qualifiers then the policy OID and qualifiers need to
  279. be specified in a separate section: this is done by using the @section syntax
  280. instead of a literal OID value.
  281. The section referred to must include the policy OID using the name
  282. policyIdentifier, cPSuri qualifiers can be included using the syntax:
  283. CPS.nnn=value
  284. userNotice qualifiers can be set using the syntax:
  285. userNotice.nnn=@notice
  286. The value of the userNotice qualifier is specified in the relevant section.
  287. This section can include explicitText, organization and noticeNumbers
  288. options. explicitText and organization are text strings, noticeNumbers is a
  289. comma separated list of numbers. The organization and noticeNumbers options
  290. (if included) must BOTH be present. If you use the userNotice option with IE5
  291. then you need the 'ia5org' option at the top level to modify the encoding:
  292. otherwise it will not be interpreted properly.
  293. Example:
  294. certificatePolicies=ia5org,1.2.3.4,1.5.6.7.8,@polsect
  295. [polsect]
  296. policyIdentifier = 1.3.5.8
  297. CPS.1="http://my.host.name/"
  298. CPS.2="http://my.your.name/"
  299. userNotice.1=@notice
  300. [notice]
  301. explicitText="Explicit Text Here"
  302. organization="Organisation Name"
  303. noticeNumbers=1,2,3,4
  304. TECHNICAL NOTE: the ia5org option changes the type of the 'organization' field,
  305. according to PKIX it should be of type DisplayText but Verisign uses an
  306. IA5STRING and IE5 needs this too.
  307. Display only extensions.
  308. Some extensions are only partially supported and currently are only displayed
  309. but cannot be set. These include private key usage period, CRL number, and
  310. CRL reason.
  311. ==============================================================================
  312. X509V3 Extension code: programmers guide
  313. ==============================================================================
  314. The purpose of the extension code is twofold. It allows an extension to be
  315. created from a string or structure describing its contents and it prints out an
  316. extension in a human or machine readable form.
  317. 1. Initialisation and cleanup.
  318. No special initialisation is needed before calling the extension functions.
  319. You used to have to call X509V3_add_standard_extensions(); but this is no longer
  320. required and this function no longer does anything.
  321. void X509V3_EXT_cleanup(void);
  322. This function should be called to cleanup the extension code if any custom
  323. extensions have been added. If no custom extensions have been added then this
  324. call does nothing. After this call all custom extension code is freed up but
  325. you can still use the standard extensions.
  326. 2. Printing and parsing extensions.
  327. The simplest way to print out extensions is via the standard X509 printing
  328. routines: if you use the standard X509_print() function, the supported
  329. extensions will be printed out automatically.
  330. The following functions allow finer control over extension display:
  331. int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
  332. int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
  333. These two functions print out an individual extension to a BIO or FILE pointer.
  334. Currently the flag argument is unused and should be set to 0. The 'indent'
  335. argument is the number of spaces to indent each line.
  336. void *X509V3_EXT_d2i(X509_EXTENSION *ext);
  337. This function parses an extension and returns its internal structure. The
  338. precise structure you get back depends on the extension being parsed. If the
  339. extension if basicConstraints you will get back a pointer to a
  340. BASIC_CONSTRAINTS structure. Check out the source in crypto/x509v3 for more
  341. details about the structures returned. The returned structure should be freed
  342. after use using the relevant free function, BASIC_CONSTRAINTS_free() for
  343. example.
  344. void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
  345. void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);
  346. void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);
  347. void * X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx);
  348. These functions combine the operations of searching for extensions and
  349. parsing them. They search a certificate, a CRL a CRL entry or a stack
  350. of extensions respectively for extension whose NID is 'nid' and return
  351. the parsed result of NULL if an error occurred. For example:
  352. BASIC_CONSTRAINTS *bs;
  353. bs = X509_get_ext_d2i(cert, NID_basic_constraints, NULL, NULL);
  354. This will search for the basicConstraints extension and either return
  355. it value or NULL. NULL can mean either the extension was not found, it
  356. occurred more than once or it could not be parsed.
  357. If 'idx' is NULL then an extension is only parsed if it occurs precisely
  358. once. This is standard behaviour because extensions normally cannot occur
  359. more than once. If however more than one extension of the same type can
  360. occur it can be used to parse successive extensions for example:
  361. int i;
  362. void *ext;
  363. i = -1;
  364. for(;;) {
  365. ext = X509_get_ext_d2i(x, nid, crit, &idx);
  366. if(ext == NULL) break;
  367. /* Do something with ext */
  368. }
  369. If 'crit' is not NULL and the extension was found then the int it points to
  370. is set to 1 for critical extensions and 0 for non critical. Therefore if the
  371. function returns NULL but 'crit' is set to 0 or 1 then the extension was
  372. found but it could not be parsed.
  373. The int pointed to by crit will be set to -1 if the extension was not found
  374. and -2 if the extension occurred more than once (this will only happen if
  375. idx is NULL). In both cases the function will return NULL.
  376. 3. Generating extensions.
  377. An extension will typically be generated from a configuration file, or some
  378. other kind of configuration database.
  379. int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
  380. X509 *cert);
  381. int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
  382. X509_CRL *crl);
  383. These functions add all the extensions in the given section to the given
  384. certificate or CRL. They will normally be called just before the certificate
  385. or CRL is due to be signed. Both return 0 on error on non zero for success.
  386. In each case 'conf' is the LHASH pointer of the configuration file to use
  387. and 'section' is the section containing the extension details.
  388. See the 'context functions' section for a description of the ctx parameter.
  389. X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
  390. char *value);
  391. This function returns an extension based on a name and value pair, if the
  392. pair will not need to access other sections in a config file (or there is no
  393. config file) then the 'conf' parameter can be set to NULL.
  394. X509_EXTENSION *X509V3_EXT_conf_nid(char *conf, X509V3_CTX *ctx, int nid,
  395. char *value);
  396. This function creates an extension in the same way as X509V3_EXT_conf() but
  397. takes the NID of the extension rather than its name.
  398. For example to produce basicConstraints with the CA flag and a path length of
  399. 10:
  400. x = X509V3_EXT_conf_nid(NULL, NULL, NID_basic_constraints,"CA:TRUE,pathlen:10");
  401. X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
  402. This function sets up an extension from its internal structure. The ext_nid
  403. parameter is the NID of the extension and 'crit' is the critical flag.
  404. 4. Context functions.
  405. The following functions set and manipulate an extension context structure.
  406. The purpose of the extension context is to allow the extension code to
  407. access various structures relating to the "environment" of the certificate:
  408. for example the issuers certificate or the certificate request.
  409. void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
  410. X509_REQ *req, X509_CRL *crl, int flags);
  411. This function sets up an X509V3_CTX structure with details of the certificate
  412. environment: specifically the issuers certificate, the subject certificate,
  413. the certificate request and the CRL: if these are not relevant or not
  414. available then they can be set to NULL. The 'flags' parameter should be set
  415. to zero.
  416. X509V3_set_ctx_test(ctx)
  417. This macro is used to set the 'ctx' structure to a 'test' value: this is to
  418. allow the syntax of an extension (or configuration file) to be tested.
  419. X509V3_set_ctx_nodb(ctx)
  420. This macro is used when no configuration database is present.
  421. void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
  422. This function is used to set the configuration database when it is an LHASH
  423. structure: typically a configuration file.
  424. The following functions are used to access a configuration database: they
  425. should only be used in RAW extensions.
  426. char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
  427. This function returns the value of the parameter "name" in "section", or NULL
  428. if there has been an error.
  429. void X509V3_string_free(X509V3_CTX *ctx, char *str);
  430. This function frees up the string returned by the above function.
  431. STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
  432. This function returns a whole section as a STACK_OF(CONF_VALUE) .
  433. void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
  434. This function frees up the STACK returned by the above function.
  435. Note: it is possible to use the extension code with a custom configuration
  436. database. To do this the "db_meth" element of the X509V3_CTX structure should
  437. be set to an X509V3_CTX_METHOD structure. This structure contains the following
  438. function pointers:
  439. char * (*get_string)(void *db, char *section, char *value);
  440. STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
  441. void (*free_string)(void *db, char * string);
  442. void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
  443. these will be called and passed the 'db' element in the X509V3_CTX structure
  444. to access the database. If a given function is not implemented or not required
  445. it can be set to NULL.
  446. 5. String helper functions.
  447. There are several "i2s" and "s2i" functions that convert structures to and
  448. from ASCII strings. In all the "i2s" cases the returned string should be
  449. freed using Free() after use. Since some of these are part of other extension
  450. code they may take a 'method' parameter. Unless otherwise stated it can be
  451. safely set to NULL.
  452. char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct);
  453. This returns a hex string from an ASN1_OCTET_STRING.
  454. char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
  455. char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
  456. These return a string decimal representations of an ASN1_INTEGER and an
  457. ASN1_ENUMERATED type, respectively.
  458. ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
  459. X509V3_CTX *ctx, char *str);
  460. This converts an ASCII hex string to an ASN1_OCTET_STRING.
  461. ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
  462. This converts a decimal ASCII string into an ASN1_INTEGER.
  463. 6. Multi valued extension helper functions.
  464. The following functions can be used to manipulate STACKs of CONF_VALUE
  465. structures, as used by multi valued extensions.
  466. int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
  467. This function expects a boolean value in 'value' and sets 'asn1_bool' to
  468. it. That is it sets it to 0 for FALSE or 0xff for TRUE. The following
  469. strings are acceptable: "TRUE", "true", "Y", "y", "YES", "yes", "FALSE"
  470. "false", "N", "n", "NO" or "no".
  471. int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
  472. This accepts a decimal integer of arbitrary length and sets an ASN1_INTEGER.
  473. int X509V3_add_value(const char *name, const char *value,
  474. STACK_OF(CONF_VALUE) **extlist);
  475. This simply adds a string name and value pair.
  476. int X509V3_add_value_uchar(const char *name, const unsigned char *value,
  477. STACK_OF(CONF_VALUE) **extlist);
  478. The same as above but for an unsigned character value.
  479. int X509V3_add_value_bool(const char *name, int asn1_bool,
  480. STACK_OF(CONF_VALUE) **extlist);
  481. This adds either "TRUE" or "FALSE" depending on the value of 'asn1_bool'
  482. int X509V3_add_value_bool_nf(char *name, int asn1_bool,
  483. STACK_OF(CONF_VALUE) **extlist);
  484. This is the same as above except it adds nothing if asn1_bool is FALSE.
  485. int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
  486. STACK_OF(CONF_VALUE) **extlist);
  487. This function adds the value of the ASN1_INTEGER in decimal form.
  488. 7. Other helper functions.
  489. <to be added>
  490. ADDING CUSTOM EXTENSIONS.
  491. Currently there are three types of supported extensions.
  492. String extensions are simple strings where the value is placed directly in the
  493. extensions, and the string returned is printed out.
  494. Multi value extensions are passed a STACK_OF(CONF_VALUE) name and value pairs
  495. or return a STACK_OF(CONF_VALUE).
  496. Raw extensions are just passed a BIO or a value and it is the extensions
  497. responsibility to handle all the necessary printing.
  498. There are two ways to add an extension. One is simply as an alias to an already
  499. existing extension. An alias is an extension that is identical in ASN1 structure
  500. to an existing extension but has a different OBJECT IDENTIFIER. This can be
  501. done by calling:
  502. int X509V3_EXT_add_alias(int nid_to, int nid_from);
  503. 'nid_to' is the new extension NID and 'nid_from' is the already existing
  504. extension NID.
  505. Alternatively an extension can be written from scratch. This involves writing
  506. the ASN1 code to encode and decode the extension and functions to print out and
  507. generate the extension from strings. The relevant functions are then placed in
  508. a X509V3_EXT_METHOD structure and int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
  509. called.
  510. The X509V3_EXT_METHOD structure is described below.
  511. strut {
  512. int ext_nid;
  513. int ext_flags;
  514. X509V3_EXT_NEW ext_new;
  515. X509V3_EXT_FREE ext_free;
  516. X509V3_EXT_D2I d2i;
  517. X509V3_EXT_I2D i2d;
  518. X509V3_EXT_I2S i2s;
  519. X509V3_EXT_S2I s2i;
  520. X509V3_EXT_I2V i2v;
  521. X509V3_EXT_V2I v2i;
  522. X509V3_EXT_R2I r2i;
  523. X509V3_EXT_I2R i2r;
  524. void *usr_data;
  525. };
  526. The elements have the following meanings.
  527. ext_nid is the NID of the object identifier of the extension.
  528. ext_flags is set of flags. Currently the only external flag is
  529. X509V3_EXT_MULTILINE which means a multi valued extensions
  530. should be printed on separate lines.
  531. usr_data is an extension specific pointer to any relevant data. This
  532. allows extensions to share identical code but have different
  533. uses. An example of this is the bit string extension which uses
  534. usr_data to contain a list of the bit names.
  535. All the remaining elements are function pointers.
  536. ext_new is a pointer to a function that allocates memory for the
  537. extension ASN1 structure: for example ASN1_OBJECT_new().
  538. ext_free is a pointer to a function that free up memory of the extension
  539. ASN1 structure: for example ASN1_OBJECT_free().
  540. d2i is the standard ASN1 function that converts a DER buffer into
  541. the internal ASN1 structure: for example d2i_ASN1_IA5STRING().
  542. i2d is the standard ASN1 function that converts the internal
  543. structure into the DER representation: for example
  544. i2d_ASN1_IA5STRING().
  545. The remaining functions are depend on the type of extension. One i2X and
  546. one X2i should be set and the rest set to NULL. The types set do not need
  547. to match up, for example the extension could be set using the multi valued
  548. v2i function and printed out using the raw i2r.
  549. All functions have the X509V3_EXT_METHOD passed to them in the 'method'
  550. parameter and an X509V3_CTX structure. Extension code can then access the
  551. parent structure via the 'method' parameter to for example make use of the value
  552. of usr_data. If the code needs to use detail relating to the request it can
  553. use the 'ctx' parameter.
  554. A note should be given here about the 'flags' member of the 'ctx' parameter.
  555. If it has the value CTX_TEST then the configuration syntax is being checked
  556. and no actual certificate or CRL exists. Therefore any attempt in the config
  557. file to access such information should silently succeed. If the syntax is OK
  558. then it should simply return a (possibly bogus) extension, otherwise it
  559. should return NULL.
  560. char *i2s(struct v3_ext_method *method, void *ext);
  561. This function takes the internal structure in the ext parameter and returns
  562. a Malloc'ed string representing its value.
  563. void * s2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
  564. This function takes the string representation in the ext parameter and returns
  565. an allocated internal structure: ext_free() will be used on this internal
  566. structure after use.
  567. i2v and v2i handle a STACK_OF(CONF_VALUE):
  568. typedef struct
  569. {
  570. char *section;
  571. char *name;
  572. char *value;
  573. } CONF_VALUE;
  574. Only the name and value members are currently used.
  575. STACK_OF(CONF_VALUE) * i2v(struct v3_ext_method *method, void *ext);
  576. This function is passed the internal structure in the ext parameter and
  577. returns a STACK of CONF_VALUE structures. The values of name, value,
  578. section and the structure itself will be freed up with Free after use.
  579. Several helper functions are available to add values to this STACK.
  580. void * v2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx,
  581. STACK_OF(CONF_VALUE) *values);
  582. This function takes a STACK_OF(CONF_VALUE) structures and should set the
  583. values of the external structure. This typically uses the name element to
  584. determine which structure element to set and the value element to determine
  585. what to set it to. Several helper functions are available for this
  586. purpose (see above).
  587. int i2r(struct v3_ext_method *method, void *ext, BIO *out, int indent);
  588. This function is passed the internal extension structure in the ext parameter
  589. and sends out a human readable version of the extension to out. The 'indent'
  590. parameter should be noted to determine the necessary amount of indentation
  591. needed on the output.
  592. void * r2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
  593. This is just passed the string representation of the extension. It is intended
  594. to be used for more elaborate extensions where the standard single and multi
  595. valued options are insufficient. They can use the 'ctx' parameter to parse the
  596. configuration database themselves. See the context functions section for details
  597. of how to do this.
  598. Note: although this type takes the same parameters as the "r2s" function there
  599. is a subtle difference. Whereas an "r2i" function can access a configuration
  600. database an "s2i" function MUST NOT. This is so the internal code can safely
  601. assume that an "s2i" function will work without a configuration database.
  602. ==============================================================================
  603. PKCS#12 Library
  604. ==============================================================================
  605. This section describes the internal PKCS#12 support. There are very few
  606. differences between the old external library and the new internal code at
  607. present. This may well change because the external library will not be updated
  608. much in future.
  609. This version now includes a couple of high level PKCS#12 functions which
  610. generally "do the right thing" and should make it much easier to handle PKCS#12
  611. structures.
  612. HIGH LEVEL FUNCTIONS.
  613. For most applications you only need concern yourself with the high level
  614. functions. They can parse and generate simple PKCS#12 files as produced by
  615. Netscape and MSIE or indeed any compliant PKCS#12 file containing a single
  616. private key and certificate pair.
  617. 1. Initialisation and cleanup.
  618. No special initialisation is needed for the internal PKCS#12 library: the
  619. standard SSLeay_add_all_algorithms() is sufficient. If you do not wish to
  620. add all algorithms (you should at least add SHA1 though) then you can manually
  621. initialise the PKCS#12 library with:
  622. PKCS12_PBE_add();
  623. The memory allocated by the PKCS#12 library is freed up when EVP_cleanup() is
  624. called or it can be directly freed with:
  625. EVP_PBE_cleanup();
  626. after this call (or EVP_cleanup() ) no more PKCS#12 library functions should
  627. be called.
  628. 2. I/O functions.
  629. i2d_PKCS12_bio(bp, p12)
  630. This writes out a PKCS12 structure to a BIO.
  631. i2d_PKCS12_fp(fp, p12)
  632. This is the same but for a FILE pointer.
  633. d2i_PKCS12_bio(bp, p12)
  634. This reads in a PKCS12 structure from a BIO.
  635. d2i_PKCS12_fp(fp, p12)
  636. This is the same but for a FILE pointer.
  637. 3. High level functions.
  638. 3.1 Parsing with PKCS12_parse().
  639. int PKCS12_parse(PKCS12 *p12, char *pass, EVP_PKEY **pkey, X509 **cert,
  640. STACK **ca);
  641. This function takes a PKCS12 structure and a password (ASCII, null terminated)
  642. and returns the private key, the corresponding certificate and any CA
  643. certificates. If any of these is not required it can be passed as a NULL.
  644. The 'ca' parameter should be either NULL, a pointer to NULL or a valid STACK
  645. structure. Typically to read in a PKCS#12 file you might do:
  646. p12 = d2i_PKCS12_fp(fp, NULL);
  647. PKCS12_parse(p12, password, &pkey, &cert, NULL); /* CAs not wanted */
  648. PKCS12_free(p12);
  649. 3.2 PKCS#12 creation with PKCS12_create().
  650. PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
  651. STACK *ca, int nid_key, int nid_cert, int iter,
  652. int mac_iter, int keytype);
  653. This function will create a PKCS12 structure from a given password, name,
  654. private key, certificate and optional STACK of CA certificates. The remaining
  655. 5 parameters can be set to 0 and sensible defaults will be used.
  656. The parameters nid_key and nid_cert are the key and certificate encryption
  657. algorithms, iter is the encryption iteration count, mac_iter is the MAC
  658. iteration count and keytype is the type of private key. If you really want
  659. to know what these last 5 parameters do then read the low level section.
  660. Typically to create a PKCS#12 file the following could be used:
  661. p12 = PKCS12_create(pass, "My Certificate", pkey, cert, NULL, 0,0,0,0,0);
  662. i2d_PKCS12_fp(fp, p12);
  663. PKCS12_free(p12);
  664. 3.3 Changing a PKCS#12 structure password.
  665. int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
  666. This changes the password of an already existing PKCS#12 structure. oldpass
  667. is the old password and newpass is the new one. An error occurs if the old
  668. password is incorrect.
  669. LOW LEVEL FUNCTIONS.
  670. In some cases the high level functions do not provide the necessary
  671. functionality. For example if you want to generate or parse more complex
  672. PKCS#12 files. The sample pkcs12 application uses the low level functions
  673. to display details about the internal structure of a PKCS#12 file.
  674. Introduction.
  675. This is a brief description of how a PKCS#12 file is represented internally:
  676. some knowledge of PKCS#12 is assumed.
  677. A PKCS#12 object contains several levels.
  678. At the lowest level is a PKCS12_SAFEBAG. This can contain a certificate, a
  679. CRL, a private key, encrypted or unencrypted, a set of safebags (so the
  680. structure can be nested) or other secrets (not documented at present).
  681. A safebag can optionally have attributes, currently these are: a unicode
  682. friendlyName (a Unicode string) or a localKeyID (a string of bytes).
  683. At the next level is an authSafe which is a set of safebags collected into
  684. a PKCS#7 ContentInfo. This can be just plain data, or encrypted itself.
  685. At the top level is the PKCS12 structure itself which contains a set of
  686. authSafes in an embedded PKCS#7 Contentinfo of type data. In addition it
  687. contains a MAC which is a kind of password protected digest to preserve
  688. integrity (so any unencrypted stuff below can't be tampered with).
  689. The reason for these levels is so various objects can be encrypted in various
  690. ways. For example you might want to encrypt a set of private keys with
  691. triple-DES and then include the related certificates either unencrypted or
  692. with lower encryption. Yes it's the dreaded crypto laws at work again which
  693. allow strong encryption on private keys and only weak encryption on other
  694. stuff.
  695. To build one of these things you turn all certificates and keys into safebags
  696. (with optional attributes). You collect the safebags into (one or more) STACKS
  697. and convert these into authsafes (encrypted or unencrypted). The authsafes
  698. are collected into a STACK and added to a PKCS12 structure. Finally a MAC
  699. inserted.
  700. Pulling one apart is basically the reverse process. The MAC is verified against
  701. the given password. The authsafes are extracted and each authsafe split into
  702. a set of safebags (possibly involving decryption). Finally the safebags are
  703. decomposed into the original keys and certificates and the attributes used to
  704. match up private key and certificate pairs.
  705. Anyway here are the functions that do the dirty work.
  706. 1. Construction functions.
  707. 1.1 Safebag functions.
  708. M_PKCS12_x5092certbag(x509)
  709. This macro takes an X509 structure and returns a certificate bag. The
  710. X509 structure can be freed up after calling this function.
  711. M_PKCS12_x509crl2certbag(crl)
  712. As above but for a CRL.
  713. PKCS8_PRIV_KEY_INFO *PKEY2PKCS8(EVP_PKEY *pkey)
  714. Take a private key and convert it into a PKCS#8 PrivateKeyInfo structure.
  715. Works for both RSA and DSA private keys. NB since the PKCS#8 PrivateKeyInfo
  716. structure contains a private key data in plain text form it should be free'd
  717. up as soon as it has been encrypted for security reasons (freeing up the
  718. structure zeros out the sensitive data). This can be done with
  719. PKCS8_PRIV_KEY_INFO_free().
  720. PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
  721. This sets the key type when a key is imported into MSIE or Outlook 98. Two
  722. values are currently supported: KEY_EX and KEY_SIG. KEY_EX is an exchange type
  723. key that can also be used for signing but its size is limited in the export
  724. versions of MS software to 512 bits, it is also the default. KEY_SIG is a
  725. signing only key but the keysize is unlimited (well 16K is supposed to work).
  726. If you are using the domestic version of MSIE then you can ignore this because
  727. KEY_EX is not limited and can be used for both.
  728. PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8)
  729. Convert a PKCS8 private key structure into a keybag. This routine embeds the
  730. p8 structure in the keybag so p8 should not be freed up or used after it is
  731. called. The p8 structure will be freed up when the safebag is freed.
  732. PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8)
  733. Convert a PKCS#8 structure into a shrouded key bag (encrypted). p8 is not
  734. embedded and can be freed up after use.
  735. int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
  736. int PKCS12_add_friendlyname(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
  737. Add a local key id or a friendlyname to a safebag.
  738. 1.2 Authsafe functions.
  739. PKCS7 *PKCS12_pack_p7data(STACK *sk)
  740. Take a stack of safebags and convert them into an unencrypted authsafe. The
  741. stack of safebags can be freed up after calling this function.
  742. PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, STACK *bags);
  743. As above but encrypted.
  744. 1.3 PKCS12 functions.
  745. PKCS12 *PKCS12_init(int mode)
  746. Initialise a PKCS12 structure (currently mode should be NID_pkcs7_data).
  747. M_PKCS12_pack_authsafes(p12, safes)
  748. This macro takes a STACK of authsafes and adds them to a PKCS#12 structure.
  749. int PKCS12_set_mac(PKCS12 *p12, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, EVP_MD *md_type);
  750. Add a MAC to a PKCS12 structure. If EVP_MD is NULL use SHA-1, the spec suggests
  751. that SHA-1 should be used.
  752. 2. Extraction Functions.
  753. 2.1 Safebags.
  754. M_PKCS12_bag_type(bag)
  755. Return the type of "bag". Returns one of the following
  756. NID_keyBag
  757. NID_pkcs8ShroudedKeyBag 7
  758. NID_certBag 8
  759. NID_crlBag 9
  760. NID_secretBag 10
  761. NID_safeContentsBag 11
  762. M_PKCS12_cert_bag_type(bag)
  763. Returns type of certificate bag, following are understood.
  764. NID_x509Certificate 14
  765. NID_sdsiCertificate 15
  766. M_PKCS12_crl_bag_type(bag)
  767. Returns crl bag type, currently only NID_crlBag is recognised.
  768. M_PKCS12_certbag2x509(bag)
  769. This macro extracts an X509 certificate from a certificate bag.
  770. M_PKCS12_certbag2x509crl(bag)
  771. As above but for a CRL.
  772. EVP_PKEY * PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
  773. Extract a private key from a PKCS8 private key info structure.
  774. M_PKCS12_decrypt_skey(bag, pass, passlen)
  775. Decrypt a shrouded key bag and return a PKCS8 private key info structure.
  776. Works with both RSA and DSA keys
  777. char *PKCS12_get_friendlyname(bag)
  778. Returns the friendlyName of a bag if present or NULL if none. The returned
  779. string is a null terminated ASCII string allocated with Malloc(). It should
  780. thus be freed up with Free() after use.
  781. 2.2 AuthSafe functions.
  782. M_PKCS12_unpack_p7data(p7)
  783. Extract a STACK of safe bags from a PKCS#7 data ContentInfo.
  784. #define M_PKCS12_unpack_p7encdata(p7, pass, passlen)
  785. As above but for an encrypted content info.
  786. 2.3 PKCS12 functions.
  787. M_PKCS12_unpack_authsafes(p12)
  788. Extract a STACK of authsafes from a PKCS12 structure.
  789. M_PKCS12_mac_present(p12)
  790. Check to see if a MAC is present.
  791. int PKCS12_verify_mac(PKCS12 *p12, unsigned char *pass, int passlen)
  792. Verify a MAC on a PKCS12 structure. Returns an error if MAC not present.
  793. Notes.
  794. 1. All the function return 0 or NULL on error.
  795. 2. Encryption based functions take a common set of parameters. These are
  796. described below.
  797. pass, passlen
  798. ASCII password and length. The password on the MAC is called the "integrity
  799. password" the encryption password is called the "privacy password" in the
  800. PKCS#12 documentation. The passwords do not have to be the same. If -1 is
  801. passed for the length it is worked out by the function itself (currently
  802. this is sometimes done whatever is passed as the length but that may change).
  803. salt, saltlen
  804. A 'salt' if salt is NULL a random salt is used. If saltlen is also zero a
  805. default length is used.
  806. iter
  807. Iteration count. This is a measure of how many times an internal function is
  808. called to encrypt the data. The larger this value is the longer it takes, it
  809. makes dictionary attacks on passwords harder. NOTE: Some implementations do
  810. not support an iteration count on the MAC. If the password for the MAC and
  811. encryption is the same then there is no point in having a high iteration
  812. count for encryption if the MAC has no count. The MAC could be attacked
  813. and the password used for the main decryption.
  814. pbe_nid
  815. This is the NID of the password based encryption method used. The following are
  816. supported.
  817. NID_pbe_WithSHA1And128BitRC4
  818. NID_pbe_WithSHA1And40BitRC4
  819. NID_pbe_WithSHA1And3_Key_TripleDES_CBC
  820. NID_pbe_WithSHA1And2_Key_TripleDES_CBC
  821. NID_pbe_WithSHA1And128BitRC2_CBC
  822. NID_pbe_WithSHA1And40BitRC2_CBC
  823. Which you use depends on the implementation you are exporting to. "Export
  824. grade" (i.e. cryptographically challenged) products cannot support all
  825. algorithms. Typically you may be able to use any encryption on shrouded key
  826. bags but they must then be placed in an unencrypted authsafe. Other authsafes
  827. may only support 40bit encryption. Of course if you are using SSLeay
  828. throughout you can strongly encrypt everything and have high iteration counts
  829. on everything.
  830. 3. For decryption routines only the password and length are needed.
  831. 4. Unlike the external version the nid's of objects are the values of the
  832. constants: that is NID_certBag is the real nid, therefore there is no
  833. PKCS12_obj_offset() function. Note the object constants are not the same as
  834. those of the external version. If you use these constants then you will need
  835. to recompile your code.
  836. 5. With the exception of PKCS12_MAKE_KEYBAG(), after calling any function or
  837. macro of the form PKCS12_MAKE_SOMETHING(other) the "other" structure can be
  838. reused or freed up safely.