Переглянути джерело

Merge pull request #10467 from RussWhitehead/traceLevel

HPCC-18205 ZCRYPT logging can't be set until after creation

Reviewed-By: Kevin Wang <kevin.wang@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 7 роки тому
батько
коміт
ff358d40ab
2 змінених файлів з 21 додано та 25 видалено
  1. 16 20
      system/security/zcrypt/zcrypt.cpp
  2. 5 5
      system/security/zcrypt/zcrypt.ipp

+ 16 - 20
system/security/zcrypt/zcrypt.cpp

@@ -47,26 +47,28 @@ IZZIPor::~IZZIPor()
 {
 }
 
-RSAZCryptor::RSAZCryptor()
+RSAZCryptor::RSAZCryptor(unsigned traceLevel)
 {
+    setTraceLevel(traceLevel);
     init();
 }
 
-RSAZCryptor::RSAZCryptor(const char* publickey)
+RSAZCryptor::RSAZCryptor(const char* publickeyBuff, unsigned traceLevel)
 {
+    setTraceLevel(traceLevel);
     init();
-    setPublicKey(publickey);
+    setPublicKey(publickeyBuff);
 }
 
-RSAZCryptor::RSAZCryptor(const char* privatekey, const char* passphrase)
+RSAZCryptor::RSAZCryptor(const char* privatekeyBuff, const char* passphrase, unsigned traceLevel)
 {
+    setTraceLevel(traceLevel);
     init();
-    setPrivateKey(privatekey, passphrase);
+    setPrivateKey(privatekeyBuff, passphrase);
 }
 
 void RSAZCryptor::init()
 {
-    m_trace_level = 0;
     m_encoding = true;
 
     bio_err = NULL;
@@ -98,19 +100,16 @@ void RSAZCryptor::init()
 
 }
 
-int RSAZCryptor::setPublicKey(const char* publickey)
+int RSAZCryptor::setPublicKey(const char* publickeyBuff)
 {
-    if(!publickey || !*publickey)
+    if(!publickeyBuff || !*publickeyBuff)
     {
         if(m_trace_level > 0)
-            printf("Warning: publickey is empty\n");
+            printf("Warning: publickeyBuff is empty\n");
 
         return -1;
     }
 
-    if(m_trace_level > 10)
-        printf("setting publickey:\n%s\n", publickey);
-
     if(pubkey)
     {
         EVP_PKEY_free(pubkey);
@@ -132,7 +131,7 @@ int RSAZCryptor::setPublicKey(const char* publickey)
     pub_size = 0;
 
     pub_mem = BIO_new(BIO_s_mem());
-    BIO_puts(pub_mem, publickey);
+    BIO_puts(pub_mem, publickeyBuff);
     if (!(pubkey = PEM_read_bio_PUBKEY(pub_mem, NULL, NULL, NULL)))
     {
         throw_error();
@@ -153,19 +152,16 @@ int RSAZCryptor::setPublicKey(const char* publickey)
     return 0;
 }
 
-int RSAZCryptor::setPrivateKey(const char* privatekey, const char* passphrase)
+int RSAZCryptor::setPrivateKey(const char* privatekeyBuff, const char* passphrase)
 {
-    if(!privatekey || !*privatekey)
+    if(!privatekeyBuff || !*privatekeyBuff)
     {
         if(m_trace_level > 0)
-            printf("Warning: privatekey is empty\n");
+            printf("Warning: privatekeyBuff is empty\n");
 
         return -1;
     }
 
-    if(m_trace_level > 10)
-        printf("setting privatekey:\n%s\n", privatekey);
-
     if(privkey)
     {
         EVP_PKEY_free(privkey);
@@ -187,7 +183,7 @@ int RSAZCryptor::setPrivateKey(const char* privatekey, const char* passphrase)
     priv_size = 0;
 
     priv_mem = BIO_new(BIO_s_mem());
-    BIO_puts(priv_mem, privatekey);
+    BIO_puts(priv_mem, privatekeyBuff);
     if (!(privkey = PEM_read_bio_PrivateKey (priv_mem, NULL, NULL, (void*)passphrase)))
     {
         throw_error();

+ 5 - 5
system/security/zcrypt/zcrypt.ipp

@@ -232,13 +232,13 @@ private:
     ZBuffer& generate_key(int len, ZBuffer& keybuf);
 
     void init();
-    virtual int setPublicKey(const char* publickey);
-    virtual int setPrivateKey(const char* privatekey, const char* passphrase);
+    virtual int setPublicKey(const char* publickeyBuff);
+    virtual int setPrivateKey(const char* privatekeyBuff, const char* passphrase);
 
 public:
-    RSAZCryptor();
-    RSAZCryptor(const char* publickey);
-    RSAZCryptor(const char* privatekey, const char* passphrase);
+    RSAZCryptor(unsigned traceLevel = 0);
+    RSAZCryptor(const char* publickey, unsigned traceLevel = 0);
+    RSAZCryptor(const char* privatekey, const char* passphrase, unsigned traceLevel = 0);
     virtual ~RSAZCryptor();
 
     virtual ZBuffer& publickey_encrypt(int in_len, unsigned char* in, ZBuffer& result);