|
|
4418f4 |
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
4418f4 |
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
4418f4 |
*
|
|
|
4418f4 |
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
4418f4 |
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
4418f4 |
* the License. You may obtain a copy of the License at
|
|
|
4418f4 |
* http://www.mozilla.org/MPL/
|
|
|
4418f4 |
*
|
|
|
4418f4 |
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
4418f4 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
4418f4 |
* for the specific language governing rights and limitations under the
|
|
|
4418f4 |
* License.
|
|
|
4418f4 |
*
|
|
|
4418f4 |
* The Original Code is the Netscape security libraries.
|
|
|
4418f4 |
*
|
|
|
4418f4 |
* The Initial Developer of the Original Code is
|
|
|
4418f4 |
* Netscape Communications Corporation.
|
|
|
4418f4 |
* Portions created by the Initial Developer are Copyright (C) 1994-2000
|
|
|
4418f4 |
* the Initial Developer. All Rights Reserved.
|
|
|
4418f4 |
*
|
|
|
4418f4 |
* Contributor(s):
|
|
|
4418f4 |
*
|
|
|
4418f4 |
* Alternatively, the contents of this file may be used under the terms of
|
|
|
4418f4 |
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
4418f4 |
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
4418f4 |
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
4418f4 |
* of those above. If you wish to allow use of your version of this file only
|
|
|
4418f4 |
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
4418f4 |
* use your version of this file under the terms of the MPL, indicate your
|
|
|
4418f4 |
* decision by deleting the provisions above and replace them with the notice
|
|
|
4418f4 |
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
4418f4 |
* the provisions above, a recipient may use your version of this file under
|
|
|
4418f4 |
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
4418f4 |
*
|
|
|
4418f4 |
* ***** END LICENSE BLOCK ***** */
|
|
|
4418f4 |
#ifndef _SEC_UTIL_H_
|
|
|
4418f4 |
#define _SEC_UTIL_H_
|
|
|
4418f4 |
|
|
|
4418f4 |
#include <seccomon.h>
|
|
|
4418f4 |
#include <secitem.h>
|
|
|
4418f4 |
#include <prerror.h>
|
|
|
4418f4 |
#include <base64.h>
|
|
|
4418f4 |
#include <key.h>
|
|
|
4418f4 |
#include <secpkcs7.h>
|
|
|
4418f4 |
#include <secasn1.h>
|
|
|
4418f4 |
#include <secder.h>
|
|
|
4418f4 |
#include <stdio.h>
|
|
|
4418f4 |
|
|
|
4418f4 |
#define SEC_CT_PRIVATE_KEY "private-key"
|
|
|
4418f4 |
#define SEC_CT_PUBLIC_KEY "public-key"
|
|
|
4418f4 |
#define SEC_CT_CERTIFICATE "certificate"
|
|
|
4418f4 |
#define SEC_CT_CERTIFICATE_REQUEST "certificate-request"
|
|
|
4418f4 |
#define SEC_CT_PKCS7 "pkcs7"
|
|
|
4418f4 |
#define SEC_CT_CRL "crl"
|
|
|
4418f4 |
|
|
|
4418f4 |
#define NS_CERTREQ_HEADER "-----BEGIN NEW CERTIFICATE REQUEST-----"
|
|
|
4418f4 |
#define NS_CERTREQ_TRAILER "-----END NEW CERTIFICATE REQUEST-----"
|
|
|
4418f4 |
|
|
|
4418f4 |
#define NS_CERT_HEADER "-----BEGIN CERTIFICATE-----"
|
|
|
4418f4 |
#define NS_CERT_TRAILER "-----END CERTIFICATE-----"
|
|
|
4418f4 |
|
|
|
4418f4 |
#define NS_CRL_HEADER "-----BEGIN CRL-----"
|
|
|
4418f4 |
#define NS_CRL_TRAILER "-----END CRL-----"
|
|
|
4418f4 |
|
|
|
4418f4 |
/* From libsec/pcertdb.c --- it's not declared in sec.h */
|
|
|
4418f4 |
extern SECStatus SEC_AddPermCertificate(CERTCertDBHandle *handle,
|
|
|
4418f4 |
SECItem *derCert, char *nickname, CERTCertTrust *trust);
|
|
|
4418f4 |
|
|
|
4418f4 |
|
|
|
4418f4 |
#ifdef SECUTIL_NEW
|
|
|
4418f4 |
typedef int (*SECU_PPFunc)(PRFileDesc *out, SECItem *item,
|
|
|
4418f4 |
char *msg, int level);
|
|
|
4418f4 |
#else
|
|
|
4418f4 |
typedef int (*SECU_PPFunc)(FILE *out, SECItem *item, char *msg, int level);
|
|
|
4418f4 |
#endif
|
|
|
4418f4 |
|
|
|
4418f4 |
typedef struct {
|
|
|
4418f4 |
enum {
|
|
|
4418f4 |
PW_NONE = 0,
|
|
|
4418f4 |
PW_FROMFILE = 1,
|
|
|
4418f4 |
PW_PLAINTEXT = 2,
|
|
|
4418f4 |
PW_EXTERNAL = 3
|
|
|
4418f4 |
} source;
|
|
|
4418f4 |
char *data;
|
|
|
4418f4 |
} secuPWData;
|
|
|
4418f4 |
|
|
|
4418f4 |
extern char *SECU_FilePasswd(PK11SlotInfo *slot, PRBool retry, void *arg);
|
|
|
4418f4 |
extern char *SECU_NoPassword(PK11SlotInfo *slot, PRBool retry, void *arg);
|
|
|
4418f4 |
extern char *SECU_GetModulePassword(PK11SlotInfo *slot, PRBool retry, void *arg);
|
|
|
4418f4 |
|
|
|
4418f4 |
/* print out an error message */
|
|
|
4418f4 |
|
|
|
4418f4 |
extern void SECU_PrintError(char *progName, char *msg, ...)
|
|
|
4418f4 |
__attribute__((format(printf, 2, 3)));
|
|
|
4418f4 |
|
|
|
4418f4 |
/* print out a system error message */
|
|
|
4418f4 |
extern void SECU_PrintSystemError(char *progName, char *msg, ...)
|
|
|
4418f4 |
__attribute__((format(printf, 2, 3)));
|
|
|
4418f4 |
|
|
|
4418f4 |
/* Read the contents of a file into a SECItem */
|
|
|
4418f4 |
extern SECStatus SECU_FileToItem(SECItem *dst, PRFileDesc *src);
|
|
|
4418f4 |
extern SECStatus SECU_TextFileToItem(SECItem *dst, PRFileDesc *src);
|
|
|
4418f4 |
|
|
|
4418f4 |
/* Read in a DER from a file, may be ascii */
|
|
|
4418f4 |
extern SECStatus
|
|
|
4418f4 |
SECU_ReadDERFromFile(SECItem *der, PRFileDesc *inFile, PRBool ascii);
|
|
|
4418f4 |
|
|
|
4418f4 |
/* Indent based on "level" */
|
|
|
4418f4 |
extern void SECU_Indent(FILE *out, int level);
|
|
|
4418f4 |
|
|
|
4418f4 |
/* Print ObjectIdentifier symbolically */
|
|
|
4418f4 |
extern SECOidTag SECU_PrintObjectID(FILE *out, SECItem *oid, char *m, int level);
|
|
|
4418f4 |
|
|
|
4418f4 |
/* Print SECItem as hex */
|
|
|
4418f4 |
extern void SECU_PrintAsHex(FILE *out, SECItem *i, const char *m, int level);
|
|
|
4418f4 |
|
|
|
4418f4 |
typedef enum {
|
|
|
4418f4 |
noKeyFound = 1,
|
|
|
4418f4 |
noSignatureMatch = 2,
|
|
|
4418f4 |
failToEncode = 3,
|
|
|
4418f4 |
failToSign = 4,
|
|
|
4418f4 |
noMem = 5
|
|
|
4418f4 |
} SignAndEncodeFuncExitStat;
|
|
|
4418f4 |
|
|
|
4418f4 |
/* call back function used in encoding of an extension. Called from
|
|
|
4418f4 |
* SECU_EncodeAndAddExtensionValue */
|
|
|
4418f4 |
typedef SECStatus (* EXTEN_EXT_VALUE_ENCODER) (PRArenaPool *extHandleArena,
|
|
|
4418f4 |
void *value, SECItem *encodedValue);
|
|
|
4418f4 |
|
|
|
4418f4 |
/* Encodes and adds extensions to the CRL or CRL entries. */
|
|
|
4418f4 |
SECStatus
|
|
|
4418f4 |
SECU_EncodeAndAddExtensionValue(PRArenaPool *arena, void *extHandle,
|
|
|
4418f4 |
void *value, PRBool criticality, int extenType,
|
|
|
4418f4 |
EXTEN_EXT_VALUE_ENCODER EncodeValueFn);
|
|
|
4418f4 |
|
|
|
4418f4 |
/* Caller ensures that dst is at least item->len*2+1 bytes long */
|
|
|
4418f4 |
void
|
|
|
4418f4 |
SECU_SECItemToHex(const SECItem * item, char * dst);
|
|
|
4418f4 |
|
|
|
4418f4 |
/* Requires 0x prefix. Case-insensitive. Will do in-place replacement if
|
|
|
4418f4 |
* successful */
|
|
|
4418f4 |
SECStatus
|
|
|
4418f4 |
SECU_SECItemHexStringToBinary(SECItem* srcdest);
|
|
|
4418f4 |
|
|
|
4418f4 |
/*
|
|
|
4418f4 |
*
|
|
|
4418f4 |
* Error messaging
|
|
|
4418f4 |
*
|
|
|
4418f4 |
*/
|
|
|
4418f4 |
|
|
|
4418f4 |
/* Return informative error string */
|
|
|
4418f4 |
char *SECU_ErrorString(int16 err);
|
|
|
4418f4 |
|
|
|
4418f4 |
|
|
|
4418f4 |
#include <secerr.h>
|
|
|
4418f4 |
#include <sslerr.h>
|
|
|
4418f4 |
|
|
|
4418f4 |
#endif /* _SEC_UTIL_H_ */
|