コード例 #1
0
ファイル: filenode.py プロジェクト: zhutony/tahoe-lafs
 def create_with_keys(self, keypair, contents,
                      version=SDMF_VERSION):
     """Call this to create a brand-new mutable file. It will create the
     shares, find homes for them, and upload the initial contents (created
     with the same rules as IClient.create_mutable_file() ). Returns a
     Deferred that fires (with the MutableFileNode instance you should
     use) when it completes.
     """
     (pubkey, privkey) = keypair
     self._pubkey, self._privkey = pubkey, privkey
     pubkey_s = rsa.der_string_from_verifying_key(self._pubkey)
     privkey_s = rsa.der_string_from_signing_key(self._privkey)
     self._writekey = hashutil.ssk_writekey_hash(privkey_s)
     self._encprivkey = self._encrypt_privkey(self._writekey, privkey_s)
     self._fingerprint = hashutil.ssk_pubkey_fingerprint_hash(pubkey_s)
     if version == MDMF_VERSION:
         self._uri = WriteableMDMFFileURI(self._writekey, self._fingerprint)
         self._protocol_version = version
     elif version == SDMF_VERSION:
         self._uri = WriteableSSKFileURI(self._writekey, self._fingerprint)
         self._protocol_version = version
     self._readkey = self._uri.readkey
     self._storage_index = self._uri.storage_index
     initial_contents = self._get_initial_contents(contents)
     return self._upload(initial_contents, None)
コード例 #2
0
    def test_keys(self):
        """
        test that two instances of 'the same' key sign and verify data
        in the same way
        """
        priv_key, pub_key = rsa.create_signing_keypair(2048)
        priv_key_str = rsa.der_string_from_signing_key(priv_key)

        self.assertIsInstance(priv_key_str, native_bytes)

        priv_key2, pub_key2 = rsa.create_signing_keypair_from_string(
            priv_key_str)

        # instead of asking "are these two keys equal", we can instead
        # test their function: can the second key verify a signature
        # produced by the first (and FAIL a signature with different
        # data)

        data_to_sign = b"test data"
        sig0 = rsa.sign_data(priv_key, data_to_sign)
        rsa.verify_signature(pub_key2, sig0, data_to_sign)

        # ..and the other way
        sig1 = rsa.sign_data(priv_key2, data_to_sign)
        rsa.verify_signature(pub_key, sig1, data_to_sign)

        # ..and a failed way
        with self.assertRaises(rsa.BadSignature):
            rsa.verify_signature(pub_key, sig1, data_to_sign + b"more")
コード例 #3
0
 def _got_key(keypair):
     (pubkey, privkey) = keypair
     nm.key_generator = SameKeyGenerator(pubkey, privkey)
     pubkey_s = rsa.der_string_from_verifying_key(pubkey)
     privkey_s = rsa.der_string_from_signing_key(privkey)
     u = uri.WriteableSSKFileURI(ssk_writekey_hash(privkey_s),
                                 ssk_pubkey_fingerprint_hash(pubkey_s))
     self._storage_index = u.get_storage_index()