Skip to content

Commit

Permalink
Implementation of the RFC 9579, PBMAC1 in PKCS#12 - documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
beldmit committed Jun 24, 2024
1 parent d698c80 commit 1fe5996
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
11 changes: 11 additions & 0 deletions doc/man1/openssl-pkcs12.pod.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ PKCS#12 output (export) options:
[B<-certpbe> I<cipher>]
[B<-descert>]
[B<-macalg> I<digest>]
[B<-pbmac1>]
[B<-pbmac1_pbkdf2_kdf_md> I<digest>]
[B<-iter> I<count>]
[B<-noiter>]
[B<-nomaciter>]
Expand Down Expand Up @@ -345,6 +347,15 @@ then both, the private key and the certificates are encrypted using triple DES.

Specify the MAC digest algorithm. If not included SHA256 will be used.

=item B<-pbmac1>

Use PBMAC1 for MAC protection of the PKCS#12 file.

=item B<-pbmac1_pbkdf2_kdf_md> I<digest>

Specify the PBKDF2 KDF digest algorithm. If not included SHA256 will be used.
Until C<-pbmac1> is specified, this parameter is ignored.

=item B<-iter> I<count>

This option specifies the iteration count for the encryption key and MAC. The
Expand Down
43 changes: 35 additions & 8 deletions doc/man3/PKCS12_gen_mac.pod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
=head1 NAME

PKCS12_gen_mac, PKCS12_setup_mac, PKCS12_set_mac,
PKCS12_verify_mac - Functions to create and manipulate a PKCS#12 structure
PKCS12_set_pbmac1_with_pbkdf2, PKCS12_verify_mac, PKCS12_get0_mac,
PKCS12_get1_pbmac1_pbkdf_param - Functions to create and manipulate a PKCS#12
MAC structure

=head1 SYNOPSIS

Expand All @@ -15,9 +17,20 @@ PKCS12_verify_mac - Functions to create and manipulate a PKCS#12 structure
int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
unsigned char *salt, int saltlen, int iter,
const EVP_MD *md_type);
int PKCS12_set_pbmac1_with_pbkdf2(PKCS12 *p12, const char *pass, int passlen,
unsigned char *salt, int saltlen, int iter,
const EVP_MD *md_type,
const char *prf_md_name);
int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
int saltlen, const EVP_MD *md_type);

void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac,
const X509_ALGOR **pmacalg,
const ASN1_OCTET_STRING **psalt,
const ASN1_INTEGER **piter,
const PKCS12 *p12);
PBKDF2PARAM *PKCS12_get1_pbmac1_pbkdf_param(const X509_ALGOR *macalg);

=head1 DESCRIPTION

PKCS12_gen_mac() generates an HMAC over the entire PKCS#12 object using the
Expand All @@ -31,10 +44,19 @@ PKCS12_setup_mac() sets the MAC part of the PKCS#12 structure with the supplied
parameters.

PKCS12_set_mac() sets the MAC and MAC parameters into the PKCS#12 object.
PKCS12_set_pbmac1_with_pbkdf2() sets the MAC and MAC parameters into the
PKCS#12 object when B<PBMAC1> is used for protection of the PKCS#12 object.

I<pass> is the passphrase to use in the HMAC. I<salt> is the salt value to use,
I<iter> is the iteration count and I<md_type> is the message digest
function to use.
I<iter> is the iteration count and I<md_type> is the message digest function to
use. I<prf_md_name> specifies the digest used for the PBKDF2 in PBMAC1 KDF.

PKCS12_get0_mac() retrieves MAC value, B<X509_ALGOR> object, I<salt>, and
I<iter> count from the PKCS12 object.

PKCS12_get1_pbmac1_pbkdf_param() retrieves B<PBKDF2PARAM> struct in case when
B<PBMAC1> is used for PKCS12 protection. In that case salt and iterations count
are encapsulated in the B<PBKDF2PARAM> struct according to RFC 9579.

=head1 NOTES

Expand All @@ -43,17 +65,22 @@ If I<salt> is NULL then a suitable salt will be generated and used.
If I<iter> is 1 then an iteration count will be omitted from the PKCS#12
structure.

PKCS12_gen_mac(), PKCS12_verify_mac() and PKCS12_set_mac() make assumptions
regarding the encoding of the given passphrase. See L<passphrase-encoding(7)>
for more information.
PKCS12_gen_mac(), PKCS12_verify_mac(), PKCS12_set_mac() and
PKCS12_set_pbmac1_with_pbkdf2() make assumptions regarding the encoding of the
given passphrase. See L<passphrase-encoding(7)> for more information.

=head1 RETURN VALUES

All functions return 1 on success and 0 if an error occurred.
All functions of integer type return 1 on success and 0 if an error occurred.

PKCS12_get1_pbmac1_pbkdf_param() return NULL in case when PBMAC1 uses an
algorithm different from B<PBKDF2> or incorrect parameters and a pointer to
B<PBKDF2PARAM> struct otherwise.

=head1 CONFORMING TO

IETF RFC 7292 (L<https://tools.ietf.org/html/rfc7292>)
IETF RFC 9579 (L<https://tools.ietf.org/html/rfc9579>)

=head1 SEE ALSO

Expand All @@ -64,7 +91,7 @@ L<passphrase-encoding(7)>

=head1 COPYRIGHT

Copyright 2021-2023 The OpenSSL Project Authors. All Rights Reserved.
Copyright 2021-2024 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use
this file except in compliance with the License. You can obtain a copy
Expand Down
1 change: 0 additions & 1 deletion util/missingcrypto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,6 @@ PKCS12_MAC_DATA_it(3)
PKCS12_PBE_add(3)
PKCS12_SAFEBAGS_it(3)
PKCS12_SAFEBAG_it(3)
PKCS12_get0_mac(3)
PKCS12_get_attr(3)
PKCS12_it(3)
PKCS12_item_pack_safebag(3)
Expand Down
1 change: 0 additions & 1 deletion util/missingcrypto111.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,6 @@ PKCS12_add_safe(3)
PKCS12_add_safes(3)
PKCS12_decrypt_skey(3)
PKCS12_gen_mac(3)
PKCS12_get0_mac(3)
PKCS12_get_attr(3)
PKCS12_get_attr_gen(3)
PKCS12_get_friendlyname(3)
Expand Down

0 comments on commit 1fe5996

Please sign in to comment.