def dvsni_gen_cert(filepath, name, r_b64, nonce, key): """Generate a DVSNI cert and save it to filepath. :param str filepath: destination to save certificate. This will overwrite any file that is currently at the location. :param str name: domain to validate :param str dvsni_r: jose base64 encoded dvsni r value :param str nonce: hex value of nonce :param key: Key to perform challenge :type key: :class:`letsencrypt.client.client.Client.Key` :returns: dvsni s value jose base64 encoded :rtype: str """ # Generate S dvsni_s = Random.get_random_bytes(CONFIG.S_SIZE) dvsni_r = le_util.jose_b64decode(r_b64) # Generate extension ext = _dvsni_gen_ext(dvsni_r, dvsni_s) cert_pem = crypto_util.make_ss_cert( key.pem, [nonce + CONFIG.INVALID_EXT, name, ext]) with open(filepath, 'w') as chall_cert_file: chall_cert_file.write(cert_pem) return le_util.jose_b64encode(dvsni_s)
def test_standard(self): """Basic test for straightline code.""" # This is a helper function that can be used for handling # open context managers more elegantly. It avoids dealing with # __enter__ and __exit__ calls. # http://www.voidspace.org.uk/python/mock/helpers.html#mock.mock_open m_open = mock.mock_open() with mock.patch("letsencrypt.client.challenge_util.open", m_open, create=True): domain = "example.com" dvsni_r = "r_value" r_b64 = le_util.jose_b64encode(dvsni_r) pem = pkg_resources.resource_string( __name__, os.path.join("testdata", "rsa256_key.pem")) key = client.Client.Key("path", pem) nonce = "12345ABCDE" s_b64 = self._call("tmp.crt", domain, r_b64, nonce, key) self.assertTrue(m_open.called) self.assertEqual(m_open.call_args[0], ("tmp.crt", 'w')) self.assertEqual(m_open().write.call_count, 1) # pylint: disable=protected-access ext = challenge_util._dvsni_gen_ext( dvsni_r, le_util.jose_b64decode(s_b64)) self._standard_check_cert( m_open().write.call_args[0][0], domain, nonce, ext)
def authorization_request(req_id, name, server_nonce, responses, key_file): """Create ACME "authorizationRequest" message. :param req_id: TODO :type req_id: TODO :param name: TODO :type name: TODO :param server_nonce: TODO :type server_nonce: TODO :param responses: TODO :type response: TODO :param key_file: TODO :type key_file: TODO :returns: ACME "authorizationRequest" message. :rtype: dict """ return { "type": "authorizationRequest", "sessionID": req_id, "nonce": server_nonce, "responses": responses, "signature": crypto_util.create_sig( name + le_util.jose_b64decode(server_nonce), key_file), }
def authorization_request(req_id, name, server_nonce, responses, key, nonce=None): """Create ACME "authorizationRequest" message. :param str req_id: SessionID from the server challenge :param str name: Hostname :param str server_nonce: Nonce from the server challenge :param list responses: List of completed challenges :param str key: Key in string form. Accepted formats are the same as for `Crypto.PublicKey.RSA.importKey`. :param str nonce: Nonce used for signature. Useful for testing. :returns: ACME "authorizationRequest" message. :rtype: dict """ return { "type": "authorizationRequest", "sessionID": req_id, "nonce": server_nonce, "responses": responses, "signature": crypto_util.create_sig(name + le_util.jose_b64decode(server_nonce), key, nonce), }
def test_standard(self): """Basic test for straightline code.""" # This is a helper function that can be used for handling # open context managers more elegantly. It avoids dealing with # __enter__ and __exit__ calls. # http://www.voidspace.org.uk/python/mock/helpers.html#mock.mock_open m_open = mock.mock_open() with mock.patch("letsencrypt.client.challenge_util.open", m_open, create=True): domain = "example.com" dvsni_r = "r_value" r_b64 = le_util.jose_b64encode(dvsni_r) pem = pkg_resources.resource_string( __name__, os.path.join("testdata", "rsa256_key.pem")) key = client.Client.Key("path", pem) nonce = "12345ABCDE" s_b64 = self._call("tmp.crt", domain, r_b64, nonce, key) self.assertTrue(m_open.called) self.assertEqual(m_open.call_args[0], ("tmp.crt", 'w')) self.assertEqual(m_open().write.call_count, 1) # pylint: disable=protected-access ext = challenge_util._dvsni_gen_ext(dvsni_r, le_util.jose_b64decode(s_b64)) self._standard_check_cert(m_open().write.call_args[0][0], domain, nonce, ext)
def authorization_request(req_id, name, server_nonce, responses, key_file): """Create ACME "authorizationRequest" message. :param req_id: TODO :type req_id: TODO :param name: TODO :type name: TODO :param server_nonce: TODO :type server_nonce: TODO :param responses: TODO :type response: TODO :param key_file: TODO :type key_file: TODO :returns: ACME "authorizationRequest" message. :rtype: dict """ return { "type": "authorizationRequest", "sessionID": req_id, "nonce": server_nonce, "responses": responses, "signature": crypto_util.create_sig(name + le_util.jose_b64decode(server_nonce), key_file), }
def authorization_request(req_id, name, server_nonce, responses, key, nonce=None): """Create ACME "authorizationRequest" message. :param str req_id: SessionID from the server challenge :param str name: Hostname :param str server_nonce: Nonce from the server challenge :param list responses: List of completed challenges :param str key: Key in string form. Accepted formats are the same as for `Crypto.PublicKey.RSA.importKey`. :param str nonce: Nonce used for signature. Useful for testing. :returns: ACME "authorizationRequest" message. :rtype: dict """ return { "type": "authorizationRequest", "sessionID": req_id, "nonce": server_nonce, "responses": responses, "signature": crypto_util.create_sig( name + le_util.jose_b64decode(server_nonce), key, nonce), }
def b64_cert_to_pem(b64_der_cert): return M2Crypto.X509.load_cert_der_string( le_util.jose_b64decode(b64_der_cert)).as_pem()
def _call(self, data): from letsencrypt.client.le_util import jose_b64decode return jose_b64decode(data)