Re: Create p12 from a .pem with only a private key

2020-02-19 Thread Dirk-Willem van Gulik
> On 20 Feb 2020, at 08:43, Dirk-Willem van Gulik  wrote:
>> On 20 Feb 2020, at 08:38, Estefania  wrote:
>> I would like to ask if it is possible to create a p12 just with a .pem with
>> private key but not certificate.
> 
> Try
> 
>   openssl req -x509 -subj /CN=foo -keyout /dev/null -nodes | openssl 
> pkcs12 -out sample.p12 -export -ce rts
> 
> to make one containing just one cert without a private key.

Sorry - that should be

openssl req -x509 -subj /CN=foo -keyout /dev/null -nodes | openssl 
pkcs12 -out x.p12 -export -nokeys

and

openssl pkcs12 -in x.p12

to test.

Dw.

Re: Create p12 from a .pem with only a private key

2020-02-19 Thread Dirk-Willem van Gulik



> On 20 Feb 2020, at 08:38, Estefania  wrote:
> 
> Hi guys.
> 
> I would like to ask if it is possible to create a p12 just with a .pem with
> private key but not certificate.

Try

openssl req -x509 -subj /CN=foo -keyout /dev/null -nodes | openssl 
pkcs12 -out sample.p12 -export -certs

to make one containing just one cert without a private key.

Dw.

Create p12 from a .pem with only a private key

2020-02-19 Thread Estefania
Hi guys.

I would like to ask if it is possible to create a p12 just with a .pem with
private key but not certificate.

Thanks



--
Sent from: http://openssl.6102.n7.nabble.com/OpenSSL-User-f3.html


Re: Questions about using Elliptic Curve ciphers in OpenSSL

2020-02-19 Thread Nicola Tuveri
I think there might be some confusion.

The "parameters" files are a legacy from when cryptosystems using "custom"
domains were not widely deprecated.
Such parameter files were required for any instance of key generation, to
make sure that a key was generated in the defined custom domain, and were
part of any key serialization because in cryptosystems that define domain
parameters a keypair is generally void of operational meaning if it isn't
associated with a domain in which that keypair can be used to perform
operations and also because when two or more peers are involved we need  to
make sure that exchanged keys belonged to the same domain in which we chose
to operate.

Nowadays the experts discourage "custom" domains (see e.g. RFC 8422), as
they bring way more disadvantages than advantages, especially considering
that the disadvantages include potential serious security pitfalls.

Historically you needed to pregenerate a domain parameters file for
ephemeral DH used in the key exchange part of the TLS handshake, because
key generation is a relatively cheap operation, but generating the big
random primes required for creating new domain parameters is a quite
demanding process: this was the params file that was provided to the
SSL/TLS backend and needed to be saved alongside keys and certificates.
With ECDH, parameter generation for custom domains is even more involved,
error prone, and the validation of custom parameters received from a peer
is very expensive and littered with risks for the overall security if not
done properly.

That being said, recommending "use named curves" just means to use
well-established and studied set of parameters that standardizing bodies
deemed recommendable for secure use: this way both peers refer to a set of
parameters with a given common name rather than explicit parameters, and
the clients can trust the evaluation done by experts rather than having to
verify the received parameters for complex mathematical properties.

Now, to the commands in your email, it must be clear that there are a few
cryptosystems involved in a generic TLS handshake:
1. key exchange: usually ephemeral ECDH
2. digital signature (to validate the handshake with the server
credentials): commonly RSA, ECDSA or EdDSA (depending on the server key
type)
3. digital signature (to validate the certificate where the CA states "this
public key belongs to this subject"): commonly RSA, ECDSA or EdDSA
(depending on the CA key type)

(We should note that 3 does not necessarily require a `verify()` operation
for every handshake, because both the issuer and the subject credentials
are static, so a certificate for a server could be validated once and
cached for later use).

1)

Ephemeral ECDH generates a new keypair for every handshake, so the parties
need to agree on which domain parameters to use.
We negotiate named curves rather than explicit parameters, and that is what
`status = SSL_CTX_set1_curves_list(ctx, "P-521:P-384:P-256");` does: both
parties specify a list of supported curves, and one in common is picked
(preference on multiple hits is an irrelevant detail here).
So no need for a parameters file here, we use a list of names, and this is
independent from the cryptosystem picked for the two digital signature
operations.

2)

The server needs to have its own keypair, this means a one-time-only keygen
operation for which parameters are necessary if we pick ECDSA as the
cryptosystem of our choice.
You can do this using explicit parameters or a named curve, and the latter
is preferred. In any case there is no need to store a parameters file after
the key has been generated, as the key parameters are saved in the key
serialization anyway, both for named and for custom curves.

There is no harm in generating an intermediary params file, but it is
superfluous, and also the fact that there is no need to create such a file
should answer to your original question about where/how it is best to store
the parameter file.

To generate such a private key without the need for an intermediate params
file you could run:

~~~sh
curve_name=prime256v1
privkey_file=mykeyout.pem

openssl genpkey \
-algorithm EC -pkeyopt ec_paramgen_curve:$curve_name \
-pkeyopt ec_param_enc:named_curve \
-outform pem -out $privkey_file
~~~

Once you have a private key you could generate a certificate signing
request (CSR) for your CA to issue a certificate for your server:

~~~sh
csr_file=mycsrout.pem
csr_config=/etc/ssl/openssl.cnf

openssl req -sha256 \
   -key $privkey_file \
   -new -out $csr_file -outform pem \
   -config $csr_config
~~~

Your CA upon receiving your CSR would do its due diligence to verify this
is a valid request, that you are indeed entitled to request such a
certificate for the requested subject, and all kinds of checks.
If the CSR meets all the CA criteria, they will proceed to generate a
certificate out of your CSR. The CA key type is often RSA, so it wouldn't
be uncommon to obtain a certificate in which th

Re: Query regarding SSL_ERROR_SSL during SSL handshake

2020-02-19 Thread Matt Caswell



On 19/02/2020 05:16, Mahendra SP wrote:
> Hi All,
> 
> We are using Openssl version 1.0.2h. When we call SSL_do_handshake,
> sometimes we notice that handshake fails with error SSL_ERROR_SSL. 
> As per the documentation for this error, it is non recoverable and fatal
> error.  Documentation also mentions to check the error queue for further
> details. Does it mean, calling SSL_get_error after SSL_ERROR_SSL will
> give exact reason for this failure? 

OpenSSL has its own error stack. SSL_ERROR_SSL means that you should
look at that error stack for further details about what caused the
problem. For example you can use ERR_print_errors_fp() to print all the
error descriptions to stdout/stderr:

https://www.openssl.org/docs/man1.1.1/man3/ERR_print_errors_fp.html

You can get more fine grained control of the error stack using the
various ERR_* functions available. See:

https://www.openssl.org/docs/man1.1.1/man3/

Matt