crmffut.h
上传用户:lyxiangda
上传日期:2007-01-12
资源大小:3042k
文件大小:14k
源码类别:

CA认证

开发平台:

WINDOWS

  1. /*
  2.  * The contents of this file are subject to the Mozilla Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/MPL/
  6.  * 
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  * 
  12.  * The Original Code is the Netscape security libraries.
  13.  * 
  14.  * The Initial Developer of the Original Code is Netscape
  15.  * Communications Corporation.  Portions created by Netscape are 
  16.  * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
  17.  * Rights Reserved.
  18.  * 
  19.  * Contributor(s):
  20.  * 
  21.  * Alternatively, the contents of this file may be used under the
  22.  * terms of the GNU General Public License Version 2 or later (the
  23.  * "GPL"), in which case the provisions of the GPL are applicable 
  24.  * instead of those above.  If you wish to allow use of your 
  25.  * version of this file only under the terms of the GPL and not to
  26.  * allow others to use your version of this file under the MPL,
  27.  * indicate your decision by deleting the provisions above and
  28.  * replace them with the notice and other provisions required by
  29.  * the GPL.  If you do not delete the provisions above, a recipient
  30.  * may use your version of this file under either the MPL or the
  31.  * GPL.
  32.  */
  33. /*
  34.  * These functions to be implemented in the future if the features
  35.  * which these functions would implement wind up being needed.
  36.  */
  37. /*
  38.  * Use this functionto create the CRMFSinglePubInfo* variables that will 
  39.  * populate the inPubInfoArray paramter for the funciton
  40.  * CRMF_CreatePKIPublicationInfo.
  41.  *
  42.  * "inPubMethod" specifies which publication method will be used
  43.  * "pubLocation" is a representation of the location where 
  44.  */
  45. extern CRMFSinglePubInfo* 
  46.       CRMF_CreateSinglePubInfo(CRMFPublicationMethod  inPubMethod,
  47.        CRMFGeneralName       *pubLocation);
  48. /*
  49.  * Create a PKIPublicationInfo that can later be passed to the function
  50.  * CRMFAddPubInfoControl.
  51.  */
  52. extern CRMFPKIPublicationInfo *
  53.      CRMF_CreatePKIPublicationInfo(CRMFPublicationAction  inAction,
  54.    CRMFSinglePubInfo    **inPubInfoArray,
  55.    int                    numPubInfo);
  56. /*
  57.  * Only call this function on a CRMFPublicationInfo that was created by
  58.  * CRMF_CreatePKIPublicationInfo that was passed in NULL for arena.
  59.  */
  60. extern SECStatus 
  61.        CRMF_DestroyPKIPublicationInfo(CRMFPKIPublicationInfo *inPubInfo);
  62. extern SECStatus CRMF_AddPubInfoControl(CRMFCertRequest        *inCertReq,
  63. CRMFPKIPublicationInfo *inPubInfo);
  64. /*
  65.  * This is to create a Cert ID Control which can later be added to 
  66.  * a certificate request.
  67.  */
  68. extern CRMFCertID* CRMF_CreateCertID(CRMFGeneralName *issuer,
  69.      long             serialNumber);
  70. extern SECStatus CRMF_DestroyCertID(CRMFCertID* certID);
  71. extern SECStatus CRMF_AddCertIDControl(CRMFCertRequest *inCertReq,
  72.        CRMFCertID      *certID);
  73. extern SECStatus 
  74.        CRMF_AddProtocolEncryptioKeyControl(CRMFCertRequest          *inCertReq,
  75.    CERTSubjectPublicKeyInfo *spki);
  76. /*
  77.  * Add the ASCII Pairs Registration Info to the Certificate Request.
  78.  * The SECItem must be an OCTET string representation.
  79.  */
  80. extern SECStatus
  81.        CRMF_AddUTF8PairsRegInfo(CRMFCertRequest *inCertReq,
  82.  SECItem         *asciiPairs);
  83. /*
  84.  * This takes a CertRequest and adds it to another CertRequest.  
  85.  */
  86. extern SECStatus
  87.        CRMF_AddCertReqToRegInfo(CRMFCertRequest *certReqToAddTo,
  88. CRMFCertRequest *certReqBeingAdded);
  89. /*
  90.  * Returns which option was used for the authInfo field of POPOSigningKeyInput
  91.  */
  92. extern CRMFPOPOSkiInputAuthChoice 
  93.        CRMF_GetSignKeyInputAuthChoice(CRMFPOPOSigningKeyInput *inKeyInput);
  94. /*
  95.  * Gets the PKMACValue associated with the POPOSigningKeyInput.
  96.  * If the POPOSigningKeyInput did not use authInfo.publicKeyMAC 
  97.  * the function returns SECFailure and the value at *destValue is unchanged.
  98.  *
  99.  * If the POPOSigningKeyInput did use authInfo.publicKeyMAC, the function
  100.  * returns SECSuccess and places the PKMACValue at *destValue.
  101.  */
  102. extern SECStatus 
  103.        CRMF_GetSignKeyInputPKMACValue(CRMFPOPOSigningKeyInput *inKeyInput,
  104.       CRMFPKMACValue          **destValue);
  105. /*
  106.  * Gets the SubjectPublicKeyInfo from the POPOSigningKeyInput
  107.  */
  108. extern CERTSubjectPublicKeyInfo *
  109.        CRMF_GetSignKeyInputPublicKey(CRMFPOPOSigningKeyInput *inKeyInput);
  110. /*
  111.  * Return the value for the PKIPublicationInfo Control.
  112.  * A return value of NULL indicates that the Control was 
  113.  * not a PKIPublicationInfo Control.  Call 
  114.  * CRMF_DestroyPKIPublicationInfo on the return value when done
  115.  * using the pointer.
  116.  */
  117. extern CRMFPKIPublicationInfo* CRMF_GetPKIPubInfo(CRMFControl *inControl);
  118. /*
  119.  * Free up a CRMFPKIPublicationInfo structure.
  120.  */
  121. extern SECStatus 
  122.        CRMF_DestroyPKIPublicationInfo(CRMFPKIPublicationInfo *inPubInfo);
  123. /*
  124.  * Get the choice used for action in this PKIPublicationInfo.
  125.  */
  126. extern CRMFPublicationAction 
  127.        CRMF_GetPublicationAction(CRMFPKIPublicationInfo *inPubInfo);
  128. /*
  129.  * Get the number of pubInfos are stored in the PKIPubicationInfo.
  130.  */
  131. extern int CRMF_GetNumPubInfos(CRMFPKIPublicationInfo *inPubInfo);
  132. /*
  133.  * Get the pubInfo at index for the given PKIPubicationInfo.
  134.  * Indexing is done like a traditional C Array. (0 .. numElements-1)
  135.  */
  136. extern CRMFSinglePubInfo* 
  137.        CRMF_GetPubInfoAtIndex(CRMFPKIPublicationInfo *inPubInfo,
  138.       int                     index);
  139. /*
  140.  * Destroy the CRMFSinglePubInfo.
  141.  */
  142. extern SECStatus CRMF_DestroySinglePubInfo(CRMFSinglePubInfo *inPubInfo);
  143. /*
  144.  * Get the pubMethod used by the SinglePubInfo.
  145.  */
  146. extern CRMFPublicationMethod 
  147.        CRMF_GetPublicationMethod(CRMFSinglePubInfo *inPubInfo);
  148. /*
  149.  * Get the pubLocation associated with the SinglePubInfo.
  150.  * A NULL return value indicates there was no pubLocation associated
  151.  * with the SinglePuInfo.
  152.  */
  153. extern CRMFGeneralName* CRMF_GetPubLocation(CRMFSinglePubInfo *inPubInfo);
  154. /*
  155.  * Get the authInfo.sender field out of the POPOSigningKeyInput.
  156.  * If the POPOSigningKeyInput did not use the authInfo the function
  157.  * returns SECFailure and the value at *destName is unchanged.
  158.  *
  159.  * If the POPOSigningKeyInput did use authInfo.sender, the function returns
  160.  * SECSuccess and puts the authInfo.sender at *destName/
  161.  */
  162. extern SECStatus CRMF_GetSignKeyInputSender(CRMFPOPOSigningKeyInput *keyInput,
  163.     CRMFGeneralName        **destName);
  164. /**************** CMMF Functions that need to be added. **********************/
  165. /*
  166.  * FUNCTION: CMMF_POPODecKeyChallContentSetNextChallenge
  167.  * INPUTS:
  168.  *    inDecKeyChall
  169.  *        The CMMFPOPODecKeyChallContent to operate on.
  170.  *    inRandom
  171.  *        The random number to use when generating the challenge,
  172.  *    inSender
  173.  *        The GeneralName representation of the sender of the challenge.
  174.  *    inPubKey
  175.  *        The public key to use when encrypting the challenge.
  176.  * NOTES:
  177.  *    This function adds a challenge to the end of the list of challenges
  178.  *    contained by 'inDecKeyChall'.  Refer to the CMMF draft on how the
  179.  *    the random number passed in and the sender's GeneralName are used
  180.  *    to generate the challenge and witness fields of the challenge.  This
  181.  *    library will use SHA1 as the one-way function for generating the 
  182.  *    witess field of the challenge.
  183.  *
  184.  * RETURN:
  185.  *    SECSuccess if generating the challenge and adding to the end of list
  186.  *    of challenges was successful.  Any other return value indicates an error
  187.  *    while trying to generate the challenge.
  188.  */
  189. extern SECStatus
  190. CMMF_POPODecKeyChallContentSetNextChallenge
  191.                                    (CMMFPOPODecKeyChallContent *inDecKeyChall,
  192.     long                        inRandom,
  193.     CERTGeneralName            *inSender,
  194.     SECKEYPublicKey            *inPubKey);
  195. /*
  196.  * FUNCTION: CMMF_POPODecKeyChallContentGetNumChallenges
  197.  * INPUTS:
  198.  *    inKeyChallCont
  199.  *        The CMMFPOPODecKeyChallContent to operate on.
  200.  * RETURN:
  201.  *    This function returns the number of CMMFChallenges are contained in 
  202.  *    the CMMFPOPODecKeyChallContent structure.
  203.  */
  204. extern int CMMF_POPODecKeyChallContentGetNumChallenges
  205.                                   (CMMFPOPODecKeyChallContent *inKeyChallCont);
  206. /*
  207.  * FUNCTION: CMMF_ChallengeGetRandomNumber
  208.  * INPUTS:
  209.  *    inChallenge
  210.  *        The CMMFChallenge to operate on.
  211.  *    inDest
  212.  *        A pointer to a user supplied buffer where the library
  213.  *        can place a copy of the random integer contatained in the
  214.  *        challenge.
  215.  * NOTES:
  216.  *    This function returns the value held in the decrypted Rand structure
  217.  *    corresponding to the random integer.  The user must call 
  218.  *    CMMF_ChallengeDecryptWitness before calling this function.  Call 
  219.  *    CMMF_ChallengeIsDecrypted to find out if the challenge has been 
  220.  *    decrypted.
  221.  *
  222.  * RETURN:
  223.  *    SECSuccess indicates the witness field has been previously decrypted
  224.  *    and the value for the random integer was successfully placed at *inDest.
  225.  *    Any other return value indicates an error and that the value at *inDest
  226.  *    is not a valid value.
  227.  */
  228. extern SECStatus CMMF_ChallengeGetRandomNumber(CMMFChallenge *inChallenge,
  229.        long          *inDest);
  230. /*
  231.  * FUNCTION: CMMF_ChallengeGetSender
  232.  * INPUTS:
  233.  *    inChallenge
  234.  *        the CMMFChallenge to operate on.
  235.  * NOTES:
  236.  *    This function returns the value held in the decrypted Rand structure
  237.  *    corresponding to the sender.  The user must call 
  238.  *    CMMF_ChallengeDecryptWitness before calling this function.  Call 
  239.  *    CMMF_ChallengeIsDecrypted to find out if the witness field has been
  240.  *    decrypted.  The user must call CERT_DestroyGeneralName after the return
  241.  *    value is no longer needed.
  242.  *
  243.  * RETURN:
  244.  *    A pointer to a copy of the sender CERTGeneralName.  A return value of
  245.  *    NULL indicates an error in trying to copy the information or that the
  246.  *    witness field has not been decrypted.
  247.  */
  248. extern CERTGeneralName* CMMF_ChallengeGetSender(CMMFChallenge *inChallenge);
  249. /*
  250.  * FUNCTION: CMMF_ChallengeGetAlgId
  251.  * INPUTS:
  252.  *    inChallenge
  253.  *        The CMMFChallenge to operate on.
  254.  *    inDestAlgId
  255.  *        A pointer to memory where a pointer to a copy of the algorithm
  256.  *        id can be placed.
  257.  * NOTES:
  258.  *    This function retrieves the one way function algorithm identifier 
  259.  *    contained within the CMMFChallenge if the optional field is present.
  260.  *
  261.  * RETURN:
  262.  *    SECSucces indicates the function was able to place a pointer to a copy of
  263.  *    the alogrithm id at *inAlgId.  If the value at *inDestAlgId is NULL, 
  264.  *    that means there was no algorithm identifier present in the 
  265.  *    CMMFChallenge.  Any other return value indicates the function was not 
  266.  *    able to make a copy of the algorithm identifier.  In this case the value 
  267.  *    at *inDestAlgId is not valid.
  268.  */
  269. extern SECStatus CMMF_ChallengeGetAlgId(CMMFChallenge  *inChallenge,
  270. SECAlgorithmID *inAlgId);
  271. /*
  272.  * FUNCTION: CMMF_DestroyChallenge
  273.  * INPUTS:
  274.  *    inChallenge
  275.  *        The CMMFChallenge to free up.
  276.  * NOTES:
  277.  *    This function frees up all the memory associated with the CMMFChallenge 
  278.  *    passed in.
  279.  * RETURN:
  280.  *    SECSuccess if freeing all the memory associated with the CMMFChallenge
  281.  *    passed in is successful.  Any other return value indicates an error 
  282.  *    while freeing the memory.
  283.  */
  284. extern SECStatus CMMF_DestroyChallenge (CMMFChallenge *inChallenge);
  285. /*
  286.  * FUNCTION: CMMF_DestroyPOPODecKeyRespContent
  287.  * INPUTS:
  288.  *    inDecKeyResp
  289.  *        The CMMFPOPODecKeyRespContent structure to free.
  290.  * NOTES:
  291.  *    This function frees up all the memory associate with the 
  292.  *    CMMFPOPODecKeyRespContent.
  293.  *
  294.  * RETURN:
  295.  *    SECSuccess if freeint up all the memory associated with the
  296.  *    CMMFPOPODecKeyRespContent structure is successful.  Any other
  297.  *    return value indicates an error while freeing the memory.
  298.  */
  299. extern SECStatus
  300.      CMMF_DestroyPOPODecKeyRespContent(CMMFPOPODecKeyRespContent *inDecKeyResp);
  301. /*
  302.  * FUNCTION: CMMF_ChallengeDecryptWitness
  303.  * INPUTS:
  304.  *    inChallenge
  305.  *        The CMMFChallenge to operate on.
  306.  *    inPrivKey
  307.  *        The private key to use to decrypt the witness field.
  308.  * NOTES:
  309.  *    This function uses the private key to decrypt the challenge field
  310.  *    contained in the CMMFChallenge.  Make sure the private key matches the
  311.  *    public key that was used to encrypt the witness.  The creator of 
  312.  *    the challenge will most likely be an RA that has the public key
  313.  *    from a Cert request.  So the private key should be the private key
  314.  *    associated with public key in that request.  This function will also
  315.  *    verify the witness field of the challenge.
  316.  *
  317.  * RETURN:
  318.  *    SECSuccess if decrypting the witness field was successful.  This does
  319.  *    not indicate that the decrypted data is valid, since the private key 
  320.  *    passed in may not be the actual key needed to properly decrypt the 
  321.  *    witness field.  Meaning that there is a decrypted structure now, but
  322.  *    may be garbage because the private key was incorrect.
  323.  *    Any other return value indicates the function could not complete the
  324.  *    decryption process.
  325.  */
  326. extern SECStatus CMMF_ChallengeDecryptWitness(CMMFChallenge    *inChallenge,
  327.       SECKEYPrivateKey *inPrivKey);
  328. /*
  329.  * FUNCTION: CMMF_ChallengeIsDecrypted
  330.  * INPUTS:
  331.  *    inChallenge
  332.  *        The CMMFChallenge to operate on.
  333.  * RETURN:
  334.  *    This is a predicate function that returns PR_TRUE if the decryption 
  335.  *    process has already been performed.  The function return PR_FALSE if 
  336.  *    the decryption process has not been performed yet.
  337.  */
  338. extern PRBool CMMF_ChallengeIsDecrypted(CMMFChallenge *inChallenge);
  339. /*
  340.  * FUNCTION: CMMF_DestroyPOPODecKeyChallContent
  341.  * INPUTS:
  342.  *    inDecKeyCont
  343.  *        The CMMFPOPODecKeyChallContent to free
  344.  * NOTES:
  345.  *    This function frees up all the memory associated with the 
  346.  *    CMMFPOPODecKeyChallContent 
  347.  * RETURN:
  348.  *    SECSuccess if freeing up all the memory associatd with the 
  349.  *    CMMFPOPODecKeyChallContent is successful.  Any other return value
  350.  *    indicates an error while freeing the memory.
  351.  *
  352.  */
  353. extern SECStatus 
  354.  CMMF_DestroyPOPODecKeyChallContent (CMMFPOPODecKeyChallContent *inDecKeyCont);