forked from certbot/certbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'github/letsencrypt/master' into pkgs_se…
…p_prep Conflicts: letsencrypt/continuity_auth.py letsencrypt_nginx/configurator.py letsencrypt_nginx/dvsni.py letsencrypt_nginx/tests/configurator_test.py letsencrypt_nginx/tests/dvsni_test.py
- Loading branch information
Showing
19 changed files
with
589 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
:mod:`letsencrypt.client.proof_of_possession` | ||
-------------------------------------------------- | ||
|
||
.. automodule:: letsencrypt.client.proof_of_possession | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
"""Proof of Possession Identifier Validation Challenge.""" | ||
import M2Crypto | ||
import os | ||
import zope.component | ||
|
||
from acme import challenges | ||
from acme import jose | ||
from acme import other | ||
|
||
from letsencrypt import interfaces | ||
from letsencrypt.display import util as display_util | ||
|
||
|
||
class ProofOfPossession(object): # pylint: disable=too-few-public-methods | ||
"""Proof of Possession Identifier Validation Challenge. | ||
Based on draft-barnes-acme, section 6.5. | ||
:ivar installer: Installer object | ||
:type installer: :class:`~letsencrypt.interfaces.IInstaller` | ||
""" | ||
def __init__(self, installer): | ||
self.installer = installer | ||
|
||
def perform(self, achall): | ||
"""Perform the Proof of Possession Challenge. | ||
:param achall: Proof of Possession Challenge | ||
:type achall: :class:`letsencrypt.achallenges.ProofOfPossession` | ||
:returns: Response or None/False if the challenge cannot be completed | ||
:rtype: :class:`acme.challenges.ProofOfPossessionResponse` | ||
or False | ||
""" | ||
if (achall.alg in [jose.HS256, jose.HS384, jose.HS512] or | ||
not isinstance(achall.hints.jwk, achall.alg.kty)): | ||
return None | ||
|
||
for cert, key, _ in self.installer.get_all_certs_keys(): | ||
der_cert_key = M2Crypto.X509.load_cert(cert).get_pubkey().as_der() | ||
try: | ||
cert_key = achall.alg.kty.load(der_cert_key) | ||
# If JWKES.load raises other exceptions, they should be caught here | ||
except (IndexError, ValueError, TypeError): | ||
continue | ||
if cert_key == achall.hints.jwk: | ||
return self._gen_response(achall, key) | ||
|
||
# Is there are different prompt we should give the user? | ||
code, key = zope.component.getUtility( | ||
interfaces.IDisplay).input( | ||
"Path to private key for identifier: %s " % achall.domain) | ||
if code != display_util.CANCEL: | ||
return self._gen_response(achall, key) | ||
|
||
# If we get here, the key wasn't found | ||
return False | ||
|
||
def _gen_response(self, achall, key_path): # pylint: disable=no-self-use | ||
"""Create the response to the Proof of Possession Challenge. | ||
:param achall: Proof of Possession Challenge | ||
:type achall: :class:`letsencrypt.achallenges.ProofOfPossession` | ||
:param str key_path: Path to the key corresponding to the hinted to | ||
public key. | ||
:returns: Response or False if the challenge cannot be completed | ||
:rtype: :class:`acme.challenges.ProofOfPossessionResponse` | ||
or False | ||
""" | ||
if os.path.isfile(key_path): | ||
with open(key_path, 'rb') as key: | ||
try: | ||
# Needs to be changed if JWKES doesn't have a key attribute | ||
jwk = achall.alg.kty.load(key.read()) | ||
sig = other.Signature.from_msg(achall.nonce, jwk.key, | ||
alg=achall.alg) | ||
except (IndexError, ValueError, TypeError, jose.errors.Error): | ||
return False | ||
return challenges.ProofOfPossessionResponse(nonce=achall.nonce, | ||
signature=sig) | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"""Tests for proof_of_possession.py""" | ||
import Crypto.PublicKey.RSA | ||
import os | ||
import pkg_resources | ||
import unittest | ||
|
||
import mock | ||
|
||
from acme import challenges | ||
from acme import jose | ||
from acme import messages2 | ||
|
||
from letsencrypt import achallenges | ||
from letsencrypt import proof_of_possession | ||
from letsencrypt.display import util as display_util | ||
|
||
|
||
BASE_PACKAGE = "letsencrypt.tests" | ||
CERT0_PATH = pkg_resources.resource_filename( | ||
BASE_PACKAGE, os.path.join("testdata", "cert.pem")) | ||
CERT1_PATH = pkg_resources.resource_filename( | ||
BASE_PACKAGE, os.path.join("testdata", "cert-san.pem")) | ||
CERT2_PATH = pkg_resources.resource_filename( | ||
BASE_PACKAGE, os.path.join("testdata", "dsa_cert.pem")) | ||
CERT2_KEY_PATH = pkg_resources.resource_filename( | ||
BASE_PACKAGE, os.path.join("testdata", "dsa512_key.pem")) | ||
CERT3_PATH = pkg_resources.resource_filename( | ||
BASE_PACKAGE, os.path.join("testdata", "matching_cert.pem")) | ||
CERT3_KEY_PATH = pkg_resources.resource_filename( | ||
BASE_PACKAGE, os.path.join("testdata", "rsa512_key.pem")) | ||
CERT3_KEY = Crypto.PublicKey.RSA.importKey(pkg_resources.resource_string( | ||
BASE_PACKAGE, os.path.join('testdata', 'rsa512_key.pem'))).publickey() | ||
|
||
|
||
class ProofOfPossessionTest(unittest.TestCase): | ||
def setUp(self): | ||
self.installer = mock.MagicMock() | ||
certs = [CERT0_PATH, CERT1_PATH, CERT2_PATH, CERT3_PATH] | ||
keys = [None, None, CERT2_KEY_PATH, CERT3_KEY_PATH] | ||
self.installer.get_all_certs_keys.return_value = zip( | ||
certs, keys, 4 * [None]) | ||
self.proof_of_pos = proof_of_possession.ProofOfPossession( | ||
self.installer) | ||
|
||
hints = challenges.ProofOfPossession.Hints( | ||
jwk=jose.JWKRSA(key=CERT3_KEY), cert_fingerprints=(), | ||
certs=(), serial_numbers=(), subject_key_identifiers=(), | ||
issuers=(), authorized_for=()) | ||
chall = challenges.ProofOfPossession( | ||
alg=jose.RS256, nonce='zczv4HMLVe_0kimJ25Juig', hints=hints) | ||
challb = messages2.ChallengeBody( | ||
chall=chall, uri="http://example", status=messages2.STATUS_PENDING) | ||
self.achall = achallenges.ProofOfPossession( | ||
challb=challb, domain="example.com") | ||
|
||
def test_perform_bad_challenge(self): | ||
hints = challenges.ProofOfPossession.Hints( | ||
jwk=jose.jwk.JWKOct(key=CERT3_KEY), cert_fingerprints=(), | ||
certs=(), serial_numbers=(), subject_key_identifiers=(), | ||
issuers=(), authorized_for=()) | ||
chall = challenges.ProofOfPossession( | ||
alg=jose.HS512, nonce='zczv4HMLVe_0kimJ25Juig', hints=hints) | ||
challb = messages2.ChallengeBody( | ||
chall=chall, uri="http://example", status=messages2.STATUS_PENDING) | ||
self.achall = achallenges.ProofOfPossession( | ||
challb=challb, domain="example.com") | ||
self.assertEqual(self.proof_of_pos.perform(self.achall), None) | ||
|
||
def test_perform_no_input(self): | ||
self.assertTrue(self.proof_of_pos.perform(self.achall).verify()) | ||
|
||
@mock.patch("letsencrypt.recovery_token.zope.component.getUtility") | ||
def test_perform_with_input(self, mock_input): | ||
# Remove the matching certificate | ||
self.installer.get_all_certs_keys.return_value.pop() | ||
mock_input().input.side_effect = [(display_util.CANCEL, ""), | ||
(display_util.OK, CERT0_PATH), | ||
(display_util.OK, "imaginary_file"), | ||
(display_util.OK, CERT3_KEY_PATH)] | ||
self.assertFalse(self.proof_of_pos.perform(self.achall)) | ||
self.assertFalse(self.proof_of_pos.perform(self.achall)) | ||
self.assertFalse(self.proof_of_pos.perform(self.achall)) | ||
self.assertTrue(self.proof_of_pos.perform(self.achall).verify()) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() # pragma: no cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-----BEGIN DSA PARAMETERS----- | ||
MIGdAkEAwebEoGBfokKQeALHHnAZMQwYU35ILEBdV8oUmzv7qpSVUoHihyqfn6GC | ||
OixAKSP8EJYcTilIqPbFbfFyOPlbLwIVANoFHEDiQgknAvKrG78pHzAJdQSPAkEA | ||
qfka5Bnl+CeEMpzVZGrOVqZE/LFdZK9eT6YtWjzqtIkf3hwXUVxJsTnBG4xmrfvl | ||
41pgNJpgu99YOYqPpS0g7A== | ||
-----END DSA PARAMETERS----- | ||
-----BEGIN DSA PRIVATE KEY----- | ||
MIH5AgEAAkEAwebEoGBfokKQeALHHnAZMQwYU35ILEBdV8oUmzv7qpSVUoHihyqf | ||
n6GCOixAKSP8EJYcTilIqPbFbfFyOPlbLwIVANoFHEDiQgknAvKrG78pHzAJdQSP | ||
AkEAqfka5Bnl+CeEMpzVZGrOVqZE/LFdZK9eT6YtWjzqtIkf3hwXUVxJsTnBG4xm | ||
rfvl41pgNJpgu99YOYqPpS0g7AJATQ2LUzjGQSM6UljcPY5I2OD9THkUR9kH2tth | ||
zZd70UoI9btrVaTizgqYShuok94glSQNK0H92JgUk3scJPaAkAIVAMDn61h6vrCE | ||
mNv063So6E+eYaIN | ||
-----END DSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIICuDCCAnWgAwIBAgIJAPjmErVMzwVLMAsGCWCGSAFlAwQDAjB3MQswCQYDVQQG | ||
EwJVUzERMA8GA1UECAwITWljaGlnYW4xEjAQBgNVBAcMCUFubiBBcmJvcjErMCkG | ||
A1UECgwiVW5pdmVyc2l0eSBvZiBNaWNoaWdhbiBhbmQgdGhlIEVGRjEUMBIGA1UE | ||
AwwLZXhhbXBsZS5jb20wHhcNMTUwNTEyMTUzOTQzWhcNMTUwNjExMTUzOTQzWjB3 | ||
MQswCQYDVQQGEwJVUzERMA8GA1UECAwITWljaGlnYW4xEjAQBgNVBAcMCUFubiBB | ||
cmJvcjErMCkGA1UECgwiVW5pdmVyc2l0eSBvZiBNaWNoaWdhbiBhbmQgdGhlIEVG | ||
RjEUMBIGA1UEAwwLZXhhbXBsZS5jb20wgfEwgakGByqGSM44BAEwgZ0CQQDB5sSg | ||
YF+iQpB4AscecBkxDBhTfkgsQF1XyhSbO/uqlJVSgeKHKp+foYI6LEApI/wQlhxO | ||
KUio9sVt8XI4+VsvAhUA2gUcQOJCCScC8qsbvykfMAl1BI8CQQCp+RrkGeX4J4Qy | ||
nNVkas5WpkT8sV1kr15Ppi1aPOq0iR/eHBdRXEmxOcEbjGat++XjWmA0mmC731g5 | ||
io+lLSDsA0MAAkBNDYtTOMZBIzpSWNw9jkjY4P1MeRRH2Qfa22HNl3vRSgj1u2tV | ||
pOLOCphKG6iT3iCVJA0rQf3YmBSTexwk9oCQo1AwTjAdBgNVHQ4EFgQUZ2DlTDGU | ||
PMwTUt0KztM6IyX61BcwHwYDVR0jBBgwFoAUZ2DlTDGUPMwTUt0KztM6IyX61Bcw | ||
DAYDVR0TBAUwAwEB/zALBglghkgBZQMEAwIDMAAwLQIVAIbMgGx+KwBr4rgqZ2Lh | ||
AAO8TegHAhQsuxpIIIphiReoWEtEJk4TqEIz/A== | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIICNzCCAeGgAwIBAgIJALizm9Y3q620MA0GCSqGSIb3DQEBCwUAMHcxCzAJBgNV | ||
BAYTAlVTMREwDwYDVQQIDAhNaWNoaWdhbjESMBAGA1UEBwwJQW5uIEFyYm9yMSsw | ||
KQYDVQQKDCJVbml2ZXJzaXR5IG9mIE1pY2hpZ2FuIGFuZCB0aGUgRUZGMRQwEgYD | ||
VQQDDAtleGFtcGxlLmNvbTAeFw0xNTA1MDkwMDI0NTJaFw0xNjA1MDgwMDI0NTJa | ||
MHcxCzAJBgNVBAYTAlVTMREwDwYDVQQIDAhNaWNoaWdhbjESMBAGA1UEBwwJQW5u | ||
IEFyYm9yMSswKQYDVQQKDCJVbml2ZXJzaXR5IG9mIE1pY2hpZ2FuIGFuZCB0aGUg | ||
RUZGMRQwEgYDVQQDDAtleGFtcGxlLmNvbTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgC | ||
QQD0thFxUTc2v6qV55wRxfwnBUOeN4bVfu5ywJqy65kzR7T1yZi5TPEiQyM7/3Hg | ||
BVy9ddFc8RX4vNZaR+ROXNEzAgMBAAGjUDBOMB0GA1UdDgQWBBRJieHEVSHKmBk0 | ||
mTExx1erzlylCjAfBgNVHSMEGDAWgBRJieHEVSHKmBk0mTExx1erzlylCjAMBgNV | ||
HRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA0EABT/nlpqOaanFSLZmWIrKv0zt63k4 | ||
bmWNMA8fYT45KYpLomsW8qXdpC82IlVKfNk7fW0UYT3HOeDSJRcycxNCTQ== | ||
-----END CERTIFICATE----- |
Oops, something went wrong.