2008-11-06 02:39:08 +08:00
|
|
|
/*
|
2023-09-07 16:59:15 +08:00
|
|
|
* Copyright 1999-2023 The OpenSSL Project Authors. All Rights Reserved.
|
1999-03-29 07:17:34 +08:00
|
|
|
*
|
2018-12-06 20:49:51 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:52:22 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1999-03-29 07:17:34 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/pkcs12.h>
|
2021-02-17 15:56:36 +08:00
|
|
|
#include "crypto/pkcs7.h"
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "p12_local.h"
|
1999-03-29 07:17:34 +08:00
|
|
|
|
|
|
|
/* Initialise a PKCS12 structure to take data */
|
|
|
|
|
2021-02-17 15:56:36 +08:00
|
|
|
PKCS12 *PKCS12_init_ex(int mode, OSSL_LIB_CTX *ctx, const char *propq)
|
1999-03-29 07:17:34 +08:00
|
|
|
{
|
|
|
|
PKCS12 *pkcs12;
|
2015-05-07 01:43:59 +08:00
|
|
|
|
|
|
|
if ((pkcs12 = PKCS12_new()) == NULL) {
|
2022-09-29 19:57:34 +08:00
|
|
|
ERR_raise(ERR_LIB_PKCS12, ERR_R_ASN1_LIB);
|
1999-03-29 07:17:34 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-09-10 23:23:14 +08:00
|
|
|
if (!ASN1_INTEGER_set(pkcs12->version, 3))
|
|
|
|
goto err;
|
1999-03-30 06:18:54 +08:00
|
|
|
pkcs12->authsafes->type = OBJ_nid2obj(mode);
|
2021-02-17 15:56:36 +08:00
|
|
|
|
|
|
|
ossl_pkcs7_set0_libctx(pkcs12->authsafes, ctx);
|
|
|
|
if (!ossl_pkcs7_set1_propq(pkcs12->authsafes, propq)) {
|
2022-09-29 19:57:34 +08:00
|
|
|
ERR_raise(ERR_LIB_PKCS12, ERR_R_PKCS7_LIB);
|
2021-02-17 15:56:36 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
1999-03-29 07:17:34 +08:00
|
|
|
switch (mode) {
|
|
|
|
case NID_pkcs7_data:
|
2015-05-07 01:43:59 +08:00
|
|
|
if ((pkcs12->authsafes->d.data = ASN1_OCTET_STRING_new()) == NULL) {
|
2022-09-29 19:57:34 +08:00
|
|
|
ERR_raise(ERR_LIB_PKCS12, ERR_R_ASN1_LIB);
|
2004-12-05 09:03:15 +08:00
|
|
|
goto err;
|
1999-03-29 07:17:34 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_PKCS12, PKCS12_R_UNSUPPORTED_PKCS12_MODE);
|
2004-12-05 09:03:15 +08:00
|
|
|
goto err;
|
1999-03-29 07:17:34 +08:00
|
|
|
}
|
|
|
|
return pkcs12;
|
2015-04-12 04:32:54 +08:00
|
|
|
|
2004-12-05 09:03:15 +08:00
|
|
|
err:
|
2015-04-12 04:32:54 +08:00
|
|
|
PKCS12_free(pkcs12);
|
2004-12-05 09:03:15 +08:00
|
|
|
return NULL;
|
1999-03-29 07:17:34 +08:00
|
|
|
}
|
2021-02-17 15:56:36 +08:00
|
|
|
|
|
|
|
PKCS12 *PKCS12_init(int mode)
|
|
|
|
{
|
|
|
|
return PKCS12_init_ex(mode, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2022-12-21 12:39:07 +08:00
|
|
|
const PKCS7_CTX *ossl_pkcs12_get0_pkcs7ctx(const PKCS12 *p12)
|
|
|
|
{
|
|
|
|
if (p12 == NULL || p12->authsafes == NULL)
|
|
|
|
return NULL;
|
|
|
|
return &p12->authsafes->ctx;
|
|
|
|
}
|