~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to third-party/qca/qca-ossl/qca-ossl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
327
327
        X509V3_CTX ctx;
328
328
        X509V3_set_ctx_nodb(&ctx);
329
329
        X509V3_set_ctx(&ctx, NULL, cert, NULL, NULL, 0);
330
 
        X509_EXTENSION *ex = X509V3_EXT_conf_nid(NULL, &ctx, NID_subject_key_identifier, "hash");
 
330
        X509_EXTENSION *ex = X509V3_EXT_conf_nid(NULL, &ctx, NID_subject_key_identifier, (char *)"hash");
331
331
        return ex;
332
332
}
333
333
 
5128
5128
                v_eof = false;
5129
5129
        }
5130
5130
 
 
5131
        // dummy verification function for SSL_set_verify()
 
5132
        static int ssl_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx)
 
5133
        {
 
5134
                Q_UNUSED(preverify_ok);
 
5135
                Q_UNUSED(x509_ctx);
 
5136
 
 
5137
                // don't terminate handshake in case of verification failure
 
5138
                return 1;
 
5139
        }
 
5140
 
5131
5141
        virtual QStringList supportedCipherSuites(const TLS::Version &version) const
5132
5142
        {
5133
5143
                OpenSSL_add_ssl_algorithms();
5692
5702
                        }
5693
5703
                }
5694
5704
 
 
5705
                // request a certificate from the client, if in server mode
 
5706
                if(serv)
 
5707
                {
 
5708
                        SSL_set_verify(ssl,
 
5709
                                SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
 
5710
                                ssl_verify_callback);
 
5711
                }
 
5712
 
5695
5713
                return true;
5696
5714
        }
5697
5715
 
6155
6173
                                i2d_PKCS7_bio(bo, p7);
6156
6174
                                //PEM_write_bio_PKCS7(bo, p7);
6157
6175
                                out = bio2ba(bo);
 
6176
                                PKCS7_free(p7);
6158
6177
                        }
6159
6178
                        else
6160
6179
                        {
6597
6616
#ifdef SHA512_DIGEST_LENGTH
6598
6617
        list += "sha512";
6599
6618
#endif
 
6619
/*
6600
6620
#ifdef OBJ_whirlpool
6601
6621
        list += "whirlpool";
6602
6622
#endif
 
6623
*/
6603
6624
        return list;
6604
6625
}
6605
6626
 
6671
6692
        {
6672
6693
        }
6673
6694
 
6674
 
        Context *clone() const
 
6695
        Provider::Context *clone() const
6675
6696
        {
6676
6697
                return new opensslInfoContext(*this);
6677
6698
        }
6692
6713
        }
6693
6714
};
6694
6715
 
 
6716
class opensslRandomContext : public RandomContext
 
6717
{
 
6718
public:
 
6719
        opensslRandomContext(QCA::Provider *p) : RandomContext(p)
 
6720
        {
 
6721
        }
 
6722
 
 
6723
        Context *clone() const
 
6724
        {
 
6725
                return new opensslRandomContext(*this);
 
6726
        }
 
6727
 
 
6728
        QCA::SecureArray nextBytes(int size)
 
6729
        {
 
6730
                QCA::SecureArray buf(size);
 
6731
                int r;
 
6732
                // FIXME: loop while we don't have enough random bytes.
 
6733
                while (true) {
 
6734
                        r = RAND_bytes((unsigned char*)(buf.data()), size);
 
6735
                        if (r == 1) break; // success
 
6736
                        r = RAND_pseudo_bytes((unsigned char*)(buf.data()),
 
6737
                                                size);
 
6738
                        if (r >= 0) break; // accept insecure random numbers
 
6739
                }
 
6740
                return buf;
 
6741
        }
 
6742
};
 
6743
 
6695
6744
}
6696
6745
 
6697
6746
using namespace opensslQCAPlugin;
6711
6760
                OpenSSL_add_all_algorithms();
6712
6761
                ERR_load_crypto_strings();
6713
6762
 
6714
 
                srand(time(NULL));
6715
 
                char buf[128];
6716
 
                for(int n = 0; n < 128; ++n)
6717
 
                        buf[n] = rand();
6718
 
                RAND_seed(buf, 128);
 
6763
                // seed the RNG if it's not seeded yet
 
6764
                if (RAND_status() == 0) {
 
6765
                        qsrand(time(NULL));
 
6766
                        char buf[128];
 
6767
                        for(int n = 0; n < 128; ++n)
 
6768
                                buf[n] = qrand();
 
6769
                        RAND_seed(buf, 128);
 
6770
                }
6719
6771
 
6720
6772
                openssl_initted = true;
6721
6773
        }
6754
6806
        QStringList features() const
6755
6807
        {
6756
6808
                QStringList list;
 
6809
                list += "random";
6757
6810
                list += all_hash_types();
6758
6811
                list += all_mac_types();
6759
6812
                list += all_cipher_types();
6780
6833
        Context *createContext(const QString &type)
6781
6834
        {
6782
6835
                //OpenSSL_add_all_digests();
6783
 
                if ( type == "info" )
 
6836
                if ( type == "random" )
 
6837
                        return new opensslRandomContext(this);
 
6838
                else if ( type == "info" )
6784
6839
                        return new opensslInfoContext(this);
6785
6840
                else if ( type == "sha1" )
6786
6841
                        return new opensslHashContext( EVP_sha1(), this, type);
6810
6865
                else if ( type == "sha512" )
6811
6866
                        return new opensslHashContext( EVP_sha512(), this, type);
6812
6867
#endif
 
6868
/*
6813
6869
#ifdef OBJ_whirlpool
6814
6870
                else if ( type == "whirlpool" )
6815
6871
                        return new opensslHashContext( EVP_whirlpool(), this, type);
6816
6872
#endif
 
6873
*/
6817
6874
                else if ( type == "pbkdf1(sha1)" )
6818
6875
                        return new opensslPbkdf1Context( EVP_sha1(), this, type );
6819
6876
                else if ( type == "pbkdf1(md2)" )