2

I meet an issue when trying to use snowflake.connector with an RSA pkcs8 key with passphrase.

When I try this code, with this kind of RSA Key: openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8

import snowflake.connector as sc

private_key_file = 'config/rsa_key.p8'
private_key_file_pwd = input(f"Give to me the passphrase of the key {private_key_file}: ")

conn_params = {
    'account': 'SFK_ORG-SRF_ISTANCE',
    'user': 'TEST_RSA',
    'private_key_file': private_key_file,
    'private_key_file_pwd': private_key_file_pwd,
    'warehouse': 'MY_WH',
    'database': 'MY_DB',
    'schema': 'MY_SCHEMA',
    'role': 'USER_ROLE'
}

conn = sc.connect(**conn_params)

I get this error:

TypeError: Password was given but private key is not encrypted.

Why?

0

1 Answer 1

-1

The problem is how snowflake.connector uses the key.
If the key is created with the option -v2 des3, es:
openssl genrsa 2048 | openssl pkcs8 -topk8 -v2 des3 -inform PEM -out rsa_key_des3.p8

then snowflake.connector uses the key.

So, using this key the previous code works.

But if I use the key shown above (openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8), the snowflake.connector doesn't require the private_key_file_pwd and the most important thing, DOESN'T WANT the private_key_file_pwd.

So with this key, the code must be in this way:

import snowflake.connector as sc

private_key_file = 'config/rsa_key.p8'

conn_params = {
 'account': 'SFK_ORG-SRF_ISTANCE',
 'user': 'TEST_RSA',
 'private_key_file': private_key_file,
 'warehouse': 'MY_WH',
 'database': 'MY_DB',
 'schema': 'MY_SCHEMA',
 'role': 'USER_ROLE'
}

conn = sc.connect(**conn_params)
Sign up to request clarification or add additional context in comments.

1 Comment

I made the required modify!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.