RE: openssl function to convert pkcs#8

2012-10-15 Thread Dave Thompson
>From: owner-openssl-us...@openssl.org On Behalf Of Sanjay Patnaik
(sanpatna)
>Sent: Friday, 12 October, 2012 16:29

>Is there any documentation available for functions like 
>PEM_read_PrivateKey, Pem_write_PrivateKey  etc.

On any correct Unix install you should have man pages.
Or online at http://www.openssl.org/docs/crypto/pem.html# .
But see below.

>My problem is that I have an asn1 encoded data (DER format) in buffer x 
>which I have to use for getting a pkcs1 format private key.

I assume this is an RSA key, otherwise PKCS1 cannot apply.

>So using d2_X509_SIG, pkcs8_decrypt, EVP_PKCS82PKEY  I can get the private
key.

Are you/someone really signing a privatekey? That's unusual.
Unless you're just using it for integrity, even though 
PKCS8 can do its own password-based integrity.   

>Can I just invoke PEM_write_PrivateKey( fp, pkey, NULL,NULL, 0, NULL, NULL)

>to get the pkcs1 encoded prvateKey ?

In 0.9.8 or earlier yes. In 1.0.0 and later, the PrivateKey 
"preferred" format is a PKCS8 containing the PKCS1 for RSA 
(and other encodings for other algorithms, not applicable here)
although I see the manpage hasn't been updated for this change.
If you want only the PKCS1 in 1.0.0 or later, use EVP_get1_RSA 
then PEM_write*_RSAPrivateKey. (Equivalent to what 0.9.8 did.)
You can similarly do either in DER with i2d_X[_bio,fp] .

You can also explicitly do PKCS8PrivateKey in any version.

For unencrypted that is the only difference. For encrypted 
privatekey, the encryption used for PrivateKey=PKCS8 is quite 
different from the encryption for "legacy" RSAPrivateKey.


__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


RES: Generating rsakey using openssl as lib

2012-10-15 Thread Leonardo Laface de Almeida
Hi all,

Just if anybody needs it, this is working:

RSA *rsa = NULL;
const EVP_CIPHER *enc=NULL;
unsigned long f4=RSA_F4;
char outfile[20];
char passout[10];
BIO *bio = NULL;
int num;

num = 1024;

memcpy(&passout[0],"teste",5);
passout[5] = '\0';
memcpy(&outfile[0],"teste_kpr.pem",13);
passout[13] = '\0';

BIGNUM *bn = BN_new();

bio = BIO_new(BIO_s_file());

BIO_write_filename(bio,outfile);

rsa = RSA_new();

if (rsa == NULL)
return;
BN_set_word(bn, f4);

RSA_generate_key_ex(rsa, num, bn, NULL);


PW_CB_DATA cb_data;
cb_data.password = passout;
cb_data.prompt_info = outfile;

PEM_write_bio_RSAPrivateKey(bio,rsa,enc,NULL,0,NULL,&cb_data);

if (bn != NULL)
BN_free(bn);

if (rsa != NULL)
RSA_free(rsa);

if (bio != NULL)
BIO_free_all(bio);

The code is for testing, I recommend whom uses it to add some consistence,
as I will.

:)

Leonardo

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


RES: Generating rsakey using openssl as lib

2012-10-15 Thread Leonardo Laface de Almeida
Thanks for reply, Dave.

I was trying to understand the functions EVP_* last week, and your
suggestion is pretty usefull because now I know it's possible make it work. 

I was following the main function in genpkey.c file and following the same
sequence for generating key pair. I've got some executing erros that took me
some hours to get it. I still have the problem and I think it might be some
errors in openssl libs.

In fact, I'm developing a library (*.dll and *.so) that make SSL connectios
(already working) and exports some usefull tools for an App. The App has
some specific features that uses the library. For example, An user selects a
document using the App, sign it and send it for a server, where the two last
tasks is provided by dll.

So, why all this? 

Because the App can't load the library with the following lines on dll code:

1. EVP_PKEY_CTX *ctx;
2. EVP_PKEY *pkey = NULL;
3. ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL);  

If the third line is commented, then the library is loaded and everything
works.

Instead this three lines, with the next two lines the App can also load the
dll and it works:

4. RSA *rsa;
5. rsa = RSA_new_method(NULL);

Therefore, I'm developing using RSA_* functions now, and I think it will
work just fine. 

It seems to be an error with some pointer from EVP_* functions. Any EVP_*
function called causes this error.

Anyway, as you said the EVC functions where recent development effort
foccus, I think this may be some error in openssl lib. I also think it might
be openssl version problem or some cross-compiling error.

In any case, if it's possible I'm not importing or compiling the openssl
libs properly, please let me know. Maibe some directive before compiling
openssl, e.g. 
I'm using Openssl version 1.0.1c

NOTICE: I'm including evp.h and rsa.h files in my header.

Thanks again.

Regards
Leonardo

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


Re: Encryption algorithm

2012-10-15 Thread Alex Chen
We only use OpenSSL_add_all_algorithms during SSL initialization, no other 
SSL_[CTX]_set_cipher_list calls are made, therefore the cipher used should be 
the default DHE-RSA-AES256-SHA then.

Alex

On Oct 14, 2012, at 3:01 PM, Dave Thompson wrote:

>> From: owner-openssl-us...@openssl.org On Behalf Of Alex Chen
>> Sent: Friday, 12 October, 2012 21:31
> 
>> The 'openssl cipher -v' command shows the following cipher suites: 
> 
>> If both the client and server uses the sample version of openssl 
>> library and they only calls OpenSSL_add_all_algorithms() 
>> to initialize the cipher list. 
>> I assume the first 'preferred' cipher,  DHE-RSA-AES256-SHA, 
>> will be used, correct?
> 
> Not necessarily.
> 
> If either client or server calls SSL_[CTX_]set_cipher_list that 
> changes the list and order of ciphersuites it uses. If not, they 
> will both use the default list, which is same default list used 
> and shown by ciphers [-v] with no argument.
> 
> The client sends its list in ClientHello. Unless you set 
> "server preference" the server chooses the first ciphersuite 
> in the client's list also in the server's list and usable.
> An RSA-DHE suite is only usable, and will only be chosen, 
> if the server has an RSA key+cert configured and either 
> a tmp_dh key (or maybe parameters?), or a tmp_dh_callback.
> (According to RFC, the cert must allow digitalSignature, 
> but I don't think openssl enforces this.)
> 
> 
> __
> OpenSSL Project http://www.openssl.org
> User Support Mailing Listopenssl-users@openssl.org
> Automated List Manager   majord...@openssl.org

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


RE: top 10 mistakes when using libopenssl?

2012-10-15 Thread Charles Mills
Whew! 

Thanks.

Charles

-Original Message-
From: owner-openssl-us...@openssl.org
[mailto:owner-openssl-us...@openssl.org] On Behalf Of Dr. Stephen Henson
Sent: Monday, October 15, 2012 9:51 AM
To: openssl-users@openssl.org
Subject: Re: top 10 mistakes when using libopenssl?

On Mon, Oct 15, 2012, Charles Mills wrote:

> Oh-oh. I'm not calling OpenSSL_add_all_algorithms() or anything real 
> similar.
> 
> I call SSL_library_init() and SSL_load_error_strings() and set up the 
> Locking callback but that's it.
> 

SSL_library_init() counts as similar to OpenSSL_add_all_algorithms() so
that's fine.

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


Re: top 10 mistakes when using libopenssl?

2012-10-15 Thread Dr. Stephen Henson
On Mon, Oct 15, 2012, Charles Mills wrote:

> Oh-oh. I'm not calling OpenSSL_add_all_algorithms() or anything real
> similar.
> 
> I call SSL_library_init() and SSL_load_error_strings() and set up the
> Locking callback but that's it.
> 

SSL_library_init() counts as similar to OpenSSL_add_all_algorithms() so that's
fine.

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


RE: top 10 mistakes when using libopenssl?

2012-10-15 Thread Charles Mills
Oh-oh. I'm not calling OpenSSL_add_all_algorithms() or anything real
similar.

I call SSL_library_init() and SSL_load_error_strings() and set up the
Locking callback but that's it.

It seems to work. Both my client code and my server code interoperate with
non-OpenSLL TLS implementation without error, and report the use of strong
SSL/TLS cipher suites.

What am I missing?

Charles
-Original Message-
From: owner-openssl-us...@openssl.org
[mailto:owner-openssl-us...@openssl.org] On Behalf Of Dr. Stephen Henson
Sent: Sunday, October 14, 2012 3:56 AM
To: openssl-users@openssl.org
Subject: Re: top 10 mistakes when using libopenssl?

On Sat, Oct 13, 2012, Ken Goldman wrote:

> On 10/10/2012 8:08 PM, Kyle Hamilton wrote:
> >Suggestions from my experience:
> 
> If you include the library, #1 for novices has to be:
> 
> 1 - Using strlen() to get the length of encrypted data.
> 
> 

I'd add...

Forgetting to call OpenSSL_add_all_algorithms or similar.


__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org


Re: openssl function to convert pkcs#8

2012-10-15 Thread Sanjay Patnaik (sanpatna)
Hi,
Is there any documentation available for functions like 
PEM_read_PrivateKey, Pem_write_PrivateKey  etc.

My problem is that I have an asn1 encoded data (DER format) in buffer x which I 
have to use for getting a pkcs1 format private key.
So using   d2_X509_SIG, pkcs8_decrypt, EVP_PKCS82PKEY  I can get the private 
key.

Can I just invoke PEM_write_PrivateKey( fp, pkey, NULL,NULL, 0, NULL, NULL)   
to get the pkcs1 encoded prvateKey ?

Sanjay


Re: Firefox unhappy with my self signed Cert

2012-10-15 Thread Derek Cole
As some additional info, I am suspecting this may be an issue with my
config file.

I am using the same config file I used to set up my certificate authority,
which has under [ req ] a couple of values plugged in - for one, prompt=no,
because I didnt want it to prompt me for values. It also has a value filled
in for distinguished_name which points to a section called [
ca_distinguished_name ] that has the values for commonName, etc, that seem
to be getting put into my CSR.

Could this be the issue? Do I need to have a separate config file for
generating my CSRs than I used for generating my CA cert?

Thanks

On Fri, Oct 12, 2012 at 11:22 AM, Derek Cole  wrote:

> So I think you were right. I used a command to view the CSR that I
> generated with the following:
>
> openssl req -new -nodes -subj "/CN=www.myserver.com" -out /tmp/file.csr
> -keyout /tmp/privkey.csr -config /my/openssl.cnf
>
> when I do this though, I noticed that my subject line, which I view with
>
> openssl req -noout -text -in /tmp/file.csr -config /my/openssl.cnf
>
>
> It seems like the file is getting created with the common name in the
> config file intsead of the one I pass it. Does it not overrride the config
> file?
>
> Thanks
>
>
>
>
> On Thu, Oct 11, 2012 at 7:55 PM, Dave Thompson wrote:
>
>> >From: owner-openssl-us...@openssl.org On Behalf Of Derek Cole
>> >Sent: Thursday, 11 October, 2012 19:03
>>
>> >i have a server that is running a custom app that can accept
>> >a SSL connection. I generate a cert on each server, that is
>> >signed by my own CA. I tested whether this worked or not by
>> >using the openssl s_client and s_server commands, and it actually
>> >worked to connect to the server using those commands. I started
>> >the server with a PEM file that contained the signed cert request,
>>
>> Nit: it contains the cert, and privatekey. A cert is NOT a signed CSR.
>>
>> >as well as the private key for that cert request. This allowed me
>> >to start the server with
>> >   openssl s_server -accept 443 -cert myfile.cert
>>
>> Note that will support connection at the SSL level, but not give
>> an HTTP response unless you type it by hand (which is hard to do).
>> Add -www to support minimal requests from browsers.
>>
>> >   and on the client side 
>>
>> >I installed my_server_cert.pem as a trusted authority in firefox,
>> >however, it still prompts that it is an "Untrusted Connection"
>> >and has the button to add security exception. [which] says "Wrong Site"
>> >and "This iste attempts to identify itself iwth invalid information"
>>
>> Most SSL clients including Firefox, unlike s_client, check that the
>> name in the server cert matches the name of the server they want,
>> almost always as a domain name. The traditional and simple way is
>> the CommonName in the server cert's Subject field is the FQDN.
>> Most clients, I'd expect including Firefox but didn't take time to test,
>> also support (1-level) wildcard, or the SubjectAlternativeName extension
>> which can have multiple domain names or wildcards or some other options
>> that are rarely used. Public CAs often call this "multi-domain", or
>> "Unified Communications" which was Microsoft's jargon for it.
>>
>> If you're doing these certs yourself and can issue whatever you want
>> free anytime, I'd go with simple, but openssl ca (or x509 -req)
>> can do SAN if you set-up the config file(s).
>>
>>
>> __
>> OpenSSL Project http://www.openssl.org
>> User Support Mailing Listopenssl-users@openssl.org
>> Automated List Manager   majord...@openssl.org
>>
>
>


[FWD] Bug report

2012-10-15 Thread Lutz Jaenicke
Forwarded to openssl-users for discussion

Best regards,
Lutz
--
Lutz Jaenicke   jaeni...@openssl.org
OpenSSL Project http://www.openssl.org/~jaenicke/
--- Begin Message ---
Hello There,

  We are facing an issue with OpenSSL. Please see the following description.

  Version of OpenSSL being effected *OpenSSL 1.0.1c*
*   *Version of the operating system being used* Windows XP*
*
*
Seems there is a limitation to the size of text that can be encrypted
through Openssl command prompt via Echo

ex:

echo 'test string 1' | openssl enc -aes-256-cbc -a -salt -pass pass:mypassword


When we are trying to encrypt large text using the above command it fails,
where as if we keep the same text in a plain text file and use the
following command

openssl aes-256-cbc -in c:\attack-plan.txt -out  c:\encryptedmessage.txt -pass
pass:mypassword


Can you please help me on this?
-- 

Regards
Satya

_
**

**

*Satyanarayana Godugula*

*Project Cordillera , Technical Integration Team*

*ESS, Inc* | *E*:
satyanarayana.godug...@essit.com
 | *T*: +1 732 572 7400 Ext 1229 | *M*: +91 8985 068166

*Unilever* | *E*:
satyanarayana.godug...@unilever.com
 | *Skype*: Satya.Godugula
<>--- End Message ---


Re: id-aes256-GCM command line encrypt+decrypt fail

2012-10-15 Thread Michel

Thanks for the explanation Mr. Henson.

I do not wish to take up too much of your time, but as I am still trying 
to understand OpenSSL, I would be grateful if you can add a few words on 
how you cope with this in TLS, and point me to the corresponding source 
code.


Thanks again,

Michel.

Le 12/10/2012 19:26, Dr. Stephen Henson a écrit :

On Fri, Oct 12, 2012, Michel wrote:


I am guessing that 'special handling' is linked to the 'no
additional authentication data' issue discussed in :
http://incog-izick.blogspot.fr/2011_08_01_archive.html


It's to do with the fact that additional parameters are required with GCM and
how the tag should be handled. It might be appropriate to handle this by
appending it to the output but that adds complications on decrypt in that you
don't know in advance where the tag is and would need to buffer tag bytes
of data until you hit EOF.

None of this is handled by the cipher BIO used by the enc command some
additional functionality will be needed for this (and CCM).

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org




__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org