| 
									
										
										
										
											2019-11-18 08:34:26 +08:00
										 |  |  | =pod | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 NAME | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_new_by_EVP_PKEY, | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_set_cipher, | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_set_passphrase, | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_set_passphrase_cb, | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_set_passphrase_ui, | 
					
						
							|  |  |  | OSSL_SERIALIZER_PUBKEY_TO_PEM_PQ, | 
					
						
							|  |  |  | OSSL_SERIALIZER_PrivateKey_TO_PEM_PQ, | 
					
						
							|  |  |  | OSSL_SERIALIZER_Parameters_TO_PEM_PQ, | 
					
						
							| 
									
										
										
										
											2020-02-12 20:05:09 +08:00
										 |  |  | OSSL_SERIALIZER_PUBKEY_TO_DER_PQ, | 
					
						
							|  |  |  | OSSL_SERIALIZER_PrivateKey_TO_DER_PQ, | 
					
						
							|  |  |  | OSSL_SERIALIZER_Parameters_TO_DER_PQ, | 
					
						
							| 
									
										
										
										
											2019-11-18 08:34:26 +08:00
										 |  |  | OSSL_SERIALIZER_PUBKEY_TO_TEXT_PQ, | 
					
						
							|  |  |  | OSSL_SERIALIZER_PrivateKey_TO_TEXT_PQ, | 
					
						
							|  |  |  | OSSL_SERIALIZER_Parameters_TO_TEXT_PQ | 
					
						
							|  |  |  | - Serializer routines to serialize EVP_PKEYs | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 SYNOPSIS | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  #include <openssl/serializer.h> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  OSSL_SERIALIZER_CTX *OSSL_SERIALIZER_CTX_new_by_EVP_PKEY(const EVP_PKEY *pkey, | 
					
						
							|  |  |  |                                                           const char *propquery); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  int OSSL_SERIALIZER_CTX_set_cipher(OSSL_SERIALIZER_CTX *ctx, | 
					
						
							|  |  |  |                                     const char *cipher_name, | 
					
						
							|  |  |  |                                     const char *propquery); | 
					
						
							|  |  |  |  int OSSL_SERIALIZER_CTX_set_passphrase(OSSL_SERIALIZER_CTX *ctx, | 
					
						
							|  |  |  |                                         const unsigned char *kstr, | 
					
						
							|  |  |  |                                         size_t klen); | 
					
						
							|  |  |  |  int OSSL_SERIALIZER_CTX_set_passphrase_cb(OSSL_SERIALIZER_CTX *ctx, int enc, | 
					
						
							|  |  |  |                                            pem_password_cb *cb, void *cbarg); | 
					
						
							|  |  |  |  int OSSL_SERIALIZER_CTX_set_passphrase_ui(OSSL_SERIALIZER_CTX *ctx, | 
					
						
							|  |  |  |                                            const UI_METHOD *ui_method, | 
					
						
							|  |  |  |                                            void *ui_data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  #define OSSL_SERIALIZER_PUBKEY_TO_PEM_PQ "format=pem,type=public" | 
					
						
							|  |  |  |  #define OSSL_SERIALIZER_PrivateKey_TO_PEM_PQ "format=pem,type=private" | 
					
						
							| 
									
										
											  
											
												Redesign the KEYMGMT libcrypto <-> provider interface - the basics
The KEYMGMT libcrypto <-> provider interface currently makes a few
assumptions:
1.  provider side domain parameters and key data isn't mutable. In
    other words, as soon as a key has been created in any (loaded,
    imported data, ...), it's set in stone.
2.  provider side domain parameters can be strictly separated from the
    key data.
This does work for the most part, but there are places where that's a
bit too rigid for the functionality that the EVP_PKEY API delivers.
Key data needs to be mutable to allow the flexibility that functions
like EVP_PKEY_copy_parameters promise, as well as to provide the
combinations of data that an EVP_PKEY is generally assumed to be able
to hold:
- domain parameters only
- public key only
- public key + private key
- domain parameters + public key
- domain parameters + public key + private key
To remedy all this, we:
1.  let go of the distinction between domain parameters and key
    material proper in the libcrypto <-> provider interface.
    As a consequence, functions that still need it gain a selection
    argument, which is a set of bits that indicate what parts of the
    key object are to be considered in a specific call.  This allows
    a reduction of very similar functions into one.
2.  Rework the libcrypto <-> provider interface so provider side key
    objects are created and destructed with a separate function, and
    get their data filled and extracted in through import and export.
(future work will see other key object constructors and other
functions to fill them with data)
Fixes #10979
squash! Redesign the KEYMGMT libcrypto <-> provider interface - the basics
Remedy 1 needs a rewrite:
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/11006)
											
										 
											2020-02-03 01:56:07 +08:00
										 |  |  |  #define OSSL_SERIALIZER_Parameters_TO_PEM_PQ "format=pem,type=parameters" | 
					
						
							| 
									
										
										
										
											2019-11-18 08:34:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-12 20:05:09 +08:00
										 |  |  |  #define OSSL_SERIALIZER_PUBKEY_TO_DER_PQ "format=der,type=public" | 
					
						
							|  |  |  |  #define OSSL_SERIALIZER_PrivateKey_TO_DER_PQ "format=der,type=private" | 
					
						
							|  |  |  |  #define OSSL_SERIALIZER_Parameters_TO_DER_PQ "format=der,type=parameters" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-18 08:34:26 +08:00
										 |  |  |  #define OSSL_SERIALIZER_PUBKEY_TO_TEXT_PQ "format=text,type=public" | 
					
						
							|  |  |  |  #define OSSL_SERIALIZER_PrivateKey_TO_TEXT_PQ "format=text,type=private" | 
					
						
							| 
									
										
											  
											
												Redesign the KEYMGMT libcrypto <-> provider interface - the basics
The KEYMGMT libcrypto <-> provider interface currently makes a few
assumptions:
1.  provider side domain parameters and key data isn't mutable. In
    other words, as soon as a key has been created in any (loaded,
    imported data, ...), it's set in stone.
2.  provider side domain parameters can be strictly separated from the
    key data.
This does work for the most part, but there are places where that's a
bit too rigid for the functionality that the EVP_PKEY API delivers.
Key data needs to be mutable to allow the flexibility that functions
like EVP_PKEY_copy_parameters promise, as well as to provide the
combinations of data that an EVP_PKEY is generally assumed to be able
to hold:
- domain parameters only
- public key only
- public key + private key
- domain parameters + public key
- domain parameters + public key + private key
To remedy all this, we:
1.  let go of the distinction between domain parameters and key
    material proper in the libcrypto <-> provider interface.
    As a consequence, functions that still need it gain a selection
    argument, which is a set of bits that indicate what parts of the
    key object are to be considered in a specific call.  This allows
    a reduction of very similar functions into one.
2.  Rework the libcrypto <-> provider interface so provider side key
    objects are created and destructed with a separate function, and
    get their data filled and extracted in through import and export.
(future work will see other key object constructors and other
functions to fill them with data)
Fixes #10979
squash! Redesign the KEYMGMT libcrypto <-> provider interface - the basics
Remedy 1 needs a rewrite:
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/11006)
											
										 
											2020-02-03 01:56:07 +08:00
										 |  |  |  #define OSSL_SERIALIZER_Parameters_TO_TEXT_PQ "format=text,type=parameters" | 
					
						
							| 
									
										
										
										
											2019-11-18 08:34:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | =head1 DESCRIPTION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_new_by_EVP_PKEY() creates a B<OSSL_SERIALIZER_CTX> | 
					
						
							|  |  |  | with a suitable attached output routine for B<EVP_PKEY>s.  It will | 
					
						
							|  |  |  | search for a serializer implementation that matches the algorithm of | 
					
						
							|  |  |  | the B<EVP_PKEY> and the property query given with I<propquery>.  It | 
					
						
							|  |  |  | will prefer to find a serializer from the same provider as the key | 
					
						
							|  |  |  | data of the B<EVP_PKEY> itself, but failing that, it will choose the | 
					
						
							|  |  |  | first serializer that supplies a generic serializing function. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | If no suitable serializer was found, OSSL_SERIALIZER_CTX_new_by_EVP_PKEY() | 
					
						
							|  |  |  | still creates a B<OSSL_SERIALIZER_CTX>, but with no associated | 
					
						
							|  |  |  | serializer (L<OSSL_SERIALIZER_CTX_get_serializer(3)> returns NULL). | 
					
						
							|  |  |  | This helps the caller distinguish between an error when creating | 
					
						
							|  |  |  | the B<OSSL_SERIALIZER_CTX>, and the lack the serializer support and | 
					
						
							|  |  |  | act accordingly. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_set_cipher() tells the implementation what cipher | 
					
						
							|  |  |  | should be used to encrypt serialized keys.  The cipher is given by | 
					
						
							|  |  |  | name I<cipher_name>.  The interpretation of that I<cipher_name> is | 
					
						
							|  |  |  | implementation dependent.  The implementation may implement the digest | 
					
						
							|  |  |  | directly itself or by other implementations, or it may choose to fetch | 
					
						
							|  |  |  | it.  If the implementation supports fetching the cipher, then it may | 
					
						
							|  |  |  | use I<propquery> as properties to be queried for when fetching. | 
					
						
							|  |  |  | I<cipher_name> may also be NULL, which will result in unencrypted | 
					
						
							|  |  |  | serialization. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_set_passphrase() gives the implementation a | 
					
						
							|  |  |  | pass phrase to use when encrypting the serialized private key. | 
					
						
							|  |  |  | Alternatively, a pass phrase callback may be specified with the | 
					
						
							|  |  |  | following functions. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_set_passphrase_cb() and | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_set_passphrase_ui() sets up a callback method that | 
					
						
							|  |  |  | the implementation can use to prompt for a pass phrase. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =for comment Note that the callback method is called indirectly, | 
					
						
							|  |  |  | through an internal B<OSSL_PASSPHRASE_CALLBACK> function. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The macros B<OSSL_SERIALIZER_PUBKEY_TO_PEM_PQ>, | 
					
						
							|  |  |  | B<OSSL_SERIALIZER_PrivateKey_TO_PEM_PQ>, | 
					
						
							|  |  |  | B<OSSL_SERIALIZER_Parameters_TO_PEM_PQ>, | 
					
						
							| 
									
										
										
										
											2020-02-12 20:05:09 +08:00
										 |  |  | B<OSSL_SERIALIZER_PUBKEY_TO_DER_PQ>, | 
					
						
							|  |  |  | B<OSSL_SERIALIZER_PrivateKey_TO_DER_PQ>, | 
					
						
							|  |  |  | B<OSSL_SERIALIZER_Parameters_TO_DER_PQ>, | 
					
						
							| 
									
										
										
										
											2019-11-18 08:34:26 +08:00
										 |  |  | B<OSSL_SERIALIZER_PUBKEY_TO_TEXT_PQ>, | 
					
						
							|  |  |  | B<OSSL_SERIALIZER_PrivateKey_TO_TEXT_PQ>, | 
					
						
							|  |  |  | B<OSSL_SERIALIZER_Parameters_TO_TEXT_PQ> are convenience macros with | 
					
						
							|  |  |  | property queries to serialize the B<EVP_PKEY> as a public key, private | 
					
						
							| 
									
										
										
										
											2020-02-12 20:05:09 +08:00
										 |  |  | key or parameters to B<PEM>, to B<DER>, or to text. | 
					
						
							| 
									
										
										
										
											2019-11-18 08:34:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | =head1 RETURN VALUES | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_new_by_EVP_PKEY() returns a pointer to a | 
					
						
							|  |  |  | B<OSSL_SERIALIZER_CTX>, or NULL if it couldn't be created. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_set_cipher(), | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_set_passphrase(), | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_set_passphrase_cb(), and | 
					
						
							|  |  |  | OSSL_SERIALIZER_CTX_set_passphrase_ui() all return 1 on success, or 0 | 
					
						
							|  |  |  | on failure. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 NOTES | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Parts of the function and macro names are made to match already | 
					
						
							|  |  |  | existing OpenSSL names. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | B<EVP_PKEY> in OSSL_SERIALIZER_CTX_new_by_EVP_PKEY() matches the type | 
					
						
							|  |  |  | name, thus making for the naming pattern | 
					
						
							|  |  |  | B<OSSL_SERIALIZER_CTX_new_by_I<TYPE>>() when new types are handled. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | B<PUBKEY>, B<PrivateKey> and B<Parameters> in the macro names match | 
					
						
							| 
									
										
										
										
											2020-06-30 03:13:07 +08:00
										 |  |  | the B<I<TYPE>> part of B<PEM_write_bio_I<TYPE>> functions as well | 
					
						
							| 
									
										
										
										
											2019-11-18 08:34:26 +08:00
										 |  |  | as B<i2d_I<TYPE>_bio> functions. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 SEE ALSO | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | L<provider(7)>, L<OSSL_SERIALIZER(3)>, L<OSSL_SERIALIZER_CTX(3)> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 HISTORY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The functions described here were added in OpenSSL 3.0. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 COPYRIGHT | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-23 20:55:52 +08:00
										 |  |  | Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-11-18 08:34:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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 | 
					
						
							|  |  |  | in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  | L<https://www.openssl.org/source/license.html>. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =cut |