15 |
15 |
"ST": "Pilsen Region",
|
16 |
16 |
"emailAddress": "root@ca.com"
|
17 |
17 |
},
|
18 |
|
"usage": {
|
19 |
|
"CA": True,
|
20 |
|
"SSL": True,
|
21 |
|
"authentication": True,
|
22 |
|
"digitalSignature": True
|
23 |
|
},
|
|
18 |
"usage": ["CA", "SSL", "authentication", "digitalSignature"],
|
24 |
19 |
"validityDays": 30
|
25 |
20 |
})
|
26 |
21 |
|
... | ... | |
37 |
32 |
"ST": "Pilsen Region",
|
38 |
33 |
"emailAddress": "inter@ca.com"
|
39 |
34 |
},
|
40 |
|
"usage": {
|
41 |
|
"CA": True,
|
42 |
|
"SSL": True,
|
43 |
|
"authentication": True,
|
44 |
|
"digitalSignature": True
|
45 |
|
},
|
|
35 |
"usage": ["CA", "SSL", "authentication", "digitalSignature"],
|
46 |
36 |
"validityDays": 30
|
47 |
37 |
})
|
48 |
38 |
|
49 |
39 |
|
50 |
40 |
def make_end_cert(server, parent, title="End certificate s.r.o.", usage=None):
|
51 |
41 |
if usage is None:
|
52 |
|
usage = {
|
53 |
|
"CA": False,
|
54 |
|
"SSL": True,
|
55 |
|
"authentication": True,
|
56 |
|
"digitalSignature": True
|
57 |
|
}
|
|
42 |
usage = ["SSL", "authentication", "digitalSignature"]
|
58 |
43 |
|
59 |
44 |
return server.post("/api/certificates", content_type="application/json", json={
|
60 |
|
"CA": parent,
|
61 |
|
"subject": {
|
62 |
|
"C": "CZ",
|
63 |
|
"CN": title,
|
64 |
|
"L": "Pilsen",
|
65 |
|
"O": title,
|
66 |
|
"OU": "IT department",
|
67 |
|
"ST": "Pilsen Region",
|
68 |
|
"emailAddress": "end@ca.com"
|
69 |
|
},
|
70 |
|
"usage": usage,
|
71 |
|
"validityDays": 30
|
|
45 |
"CA": parent,
|
|
46 |
"subject": {
|
|
47 |
"C": "CZ",
|
|
48 |
"CN": title,
|
|
49 |
"L": "Pilsen",
|
|
50 |
"O": title,
|
|
51 |
"OU": "IT department",
|
|
52 |
"ST": "Pilsen Region",
|
|
53 |
"emailAddress": "end@ca.com"
|
|
54 |
},
|
|
55 |
"usage": usage,
|
|
56 |
"validityDays": 30
|
72 |
57 |
})
|
73 |
58 |
|
74 |
59 |
|
... | ... | |
188 |
173 |
"ST": "Pilsen",
|
189 |
174 |
"emailAddress": "root@ca.com"
|
190 |
175 |
},
|
191 |
|
"usage": {
|
192 |
|
"CA": True,
|
193 |
|
"SSL": True,
|
194 |
|
"authentication": True,
|
195 |
|
"digitalSignature": True
|
196 |
|
},
|
|
176 |
"usage": ["CA", "SSL", "authentication", "digitalSignature"],
|
197 |
177 |
"validityDays": 30
|
198 |
178 |
})
|
199 |
179 |
|
... | ... | |
308 |
288 |
|
309 |
289 |
|
310 |
290 |
def test_sign_by_non_ca(server):
|
311 |
|
ret = make_end_cert(server, 2, "Fake intermediate cert s.r.o.", usage={
|
312 |
|
"CA": False,
|
313 |
|
"SSL": True,
|
314 |
|
"authentication": True,
|
315 |
|
"digitalSignature": True
|
316 |
|
})
|
|
291 |
ret = make_end_cert(server, 2, "Fake intermediate cert s.r.o.", usage=["SSL", "authentication", "digitalSignature"])
|
317 |
292 |
|
318 |
293 |
assert ret.status_code == 201
|
319 |
294 |
|
... | ... | |
324 |
299 |
assert "success" in d
|
325 |
300 |
assert d["success"]
|
326 |
301 |
|
327 |
|
ret = make_end_cert(server, 8, "End certificate signed by end certificate s.r.o.", usage={
|
328 |
|
"CA": False,
|
329 |
|
"SSL": True,
|
330 |
|
"authentication": False,
|
331 |
|
"digitalSignature": False
|
332 |
|
})
|
|
302 |
ret = make_end_cert(server, 8, "End certificate signed by end certificate s.r.o.", usage=["SSL"])
|
333 |
303 |
|
334 |
304 |
# TODO discussion -> assert ret.status_code == 400
|
335 |
305 |
assert ret.status_code == 201
|
... | ... | |
462 |
432 |
"ST": "Pilsen Region",
|
463 |
433 |
"emailAddress": "end@ca.com"
|
464 |
434 |
},
|
465 |
|
"usage": {
|
466 |
|
"CA": False,
|
467 |
|
"SSL": True,
|
468 |
|
"authentication": False,
|
469 |
|
"digitalSignature": True
|
470 |
|
},
|
|
435 |
"usage": ["SSL", "digitalSignature"],
|
471 |
436 |
"validityDays": 30
|
472 |
437 |
}
|
473 |
438 |
ret = server.post("/api/certificates", content_type="application/json", json=original)
|
... | ... | |
498 |
463 |
|
499 |
464 |
assert original["CA"] == new["CA"]
|
500 |
465 |
assert original["subject"] == new["subject"]
|
501 |
|
assert original["usage"] == new["usage"]
|
|
466 |
a = [k in original["usage"] for k, v in new["usage"].items() if v]
|
|
467 |
assert all(a)
|
502 |
468 |
assert new["status"] == "valid"
|
503 |
469 |
|
504 |
470 |
|
... | ... | |
621 |
587 |
"O": "Revoked organization",
|
622 |
588 |
"OU": "Revocation dep"
|
623 |
589 |
},
|
624 |
|
"usage": {
|
625 |
|
"CA": False,
|
626 |
|
"SSL": False,
|
627 |
|
"authentication": False,
|
628 |
|
"digitalSignature": True
|
629 |
|
},
|
|
590 |
"usage": ["digitalSignature"],
|
630 |
591 |
"validityDays": 60
|
631 |
592 |
}
|
632 |
593 |
created_ret = server.post("/api/certificates", content_type="application/json", json=certificate)
|
... | ... | |
867 |
828 |
"O": "Revoked organization",
|
868 |
829 |
"OU": "Revocation dep"
|
869 |
830 |
},
|
870 |
|
"usage": {
|
871 |
|
"CA": False,
|
872 |
|
"SSL": False,
|
873 |
|
"authentication": False,
|
874 |
|
"digitalSignature": True
|
875 |
|
},
|
|
831 |
"usage": ["digitalSignature"],
|
876 |
832 |
"validityDays": 60
|
877 |
833 |
}
|
878 |
834 |
created_ret = server.post("/api/certificates", content_type="application/json", json=certificate)
|
... | ... | |
930 |
886 |
"O": "Revoked organization",
|
931 |
887 |
"OU": "Revocation dep"
|
932 |
888 |
},
|
933 |
|
"usage": {
|
934 |
|
"CA": False,
|
935 |
|
"SSL": False,
|
936 |
|
"authentication": False,
|
937 |
|
"digitalSignature": True
|
938 |
|
},
|
|
889 |
"usage": ["digitalSignature"],
|
939 |
890 |
"validityDays": 0
|
940 |
891 |
}
|
941 |
892 |
created_ret = server.post("/api/certificates", content_type="application/json", json=certificate)
|
... | ... | |
958 |
909 |
assert "success" in ret.json
|
959 |
910 |
assert ret.json["success"]
|
960 |
911 |
assert ret.json["data"]["status"] == "expired"
|
|
912 |
|
|
913 |
def test_create_with_key_with_pass_valid(server, cryptography_service):
|
|
914 |
key_pass = "123456Seven"
|
|
915 |
key_pem = cryptography_service.create_private_key(key_pass)
|
|
916 |
|
|
917 |
certificate = {
|
|
918 |
"CA": 1,
|
|
919 |
"subject": {
|
|
920 |
"C": "CZ",
|
|
921 |
"CN": "Rare Name",
|
|
922 |
"L": "Legendary Name",
|
|
923 |
"O": "Obscure Name",
|
|
924 |
"OU": "Original Uniform"
|
|
925 |
},
|
|
926 |
"usage": ["CA", "digitalSignature"],
|
|
927 |
"validityDays": 1,
|
|
928 |
"key": {
|
|
929 |
"password": key_pass,
|
|
930 |
"key_pem": key_pem
|
|
931 |
},
|
|
932 |
}
|
|
933 |
ret = server.post("/api/certificates", content_type="application/json", json=certificate)
|
|
934 |
assert ret.status_code == 201
|
|
935 |
|
|
936 |
def test_create_with_key_with_pass_invalid_1(server, cryptography_service):
|
|
937 |
key_pass = "123456Seven"
|
|
938 |
key_pem = cryptography_service.create_private_key(key_pass)
|
|
939 |
|
|
940 |
certificate = {
|
|
941 |
"CA": 1,
|
|
942 |
"subject": {
|
|
943 |
"C": "CZ",
|
|
944 |
"CN": "Rare Name",
|
|
945 |
"L": "Legendary Name",
|
|
946 |
"O": "Obscure Name",
|
|
947 |
"OU": "Original Uniform"
|
|
948 |
},
|
|
949 |
"usage": ["CA", "digitalSignature"],
|
|
950 |
"validityDays": 1,
|
|
951 |
"key": {
|
|
952 |
"password": "whoopsiedaisy",
|
|
953 |
"key_pem": key_pem
|
|
954 |
},
|
|
955 |
}
|
|
956 |
ret = server.post("/api/certificates", content_type="application/json", json=certificate)
|
|
957 |
assert ret.status_code == 400
|
|
958 |
assert ret.json["data"] == 'The provided passphrase does not match the provided key.'
|
|
959 |
assert not ret.json["success"]
|
|
960 |
|
|
961 |
def test_create_with_key_with_pass_invalid_2(server, cryptography_service):
|
|
962 |
key_pass = "123456Seven"
|
|
963 |
|
|
964 |
certificate = {
|
|
965 |
"CA": 1,
|
|
966 |
"subject": {
|
|
967 |
"C": "CZ",
|
|
968 |
"CN": "Rare Name",
|
|
969 |
"L": "Legendary Name",
|
|
970 |
"O": "Obscure Name",
|
|
971 |
"OU": "Original Uniform"
|
|
972 |
},
|
|
973 |
"usage": ["CA", "digitalSignature"],
|
|
974 |
"validityDays": 1,
|
|
975 |
"key": {
|
|
976 |
"password": key_pass,
|
|
977 |
"key_pem": "hi im garbage and you better pray `server` survives this"
|
|
978 |
},
|
|
979 |
}
|
|
980 |
ret = server.post("/api/certificates", content_type="application/json", json=certificate)
|
|
981 |
assert ret.status_code == 400
|
|
982 |
assert ret.json["data"] == 'The provided passphrase does not match the provided key.'
|
|
983 |
assert not ret.json["success"]
|
|
984 |
|
|
985 |
def test_create_with_key_no_pass(server, cryptography_service):
|
|
986 |
key_pem = cryptography_service.create_private_key()
|
|
987 |
|
|
988 |
certificate = {
|
|
989 |
"CA": 1,
|
|
990 |
"subject": {
|
|
991 |
"C": "CZ",
|
|
992 |
"CN": "Rare Name",
|
|
993 |
"L": "Legendary Name",
|
|
994 |
"O": "Obscure Name",
|
|
995 |
"OU": "Original Uniform"
|
|
996 |
},
|
|
997 |
"usage": ["CA", "digitalSignature"],
|
|
998 |
"validityDays": 1,
|
|
999 |
"key": {
|
|
1000 |
"key_pem": key_pem
|
|
1001 |
},
|
|
1002 |
}
|
|
1003 |
ret = server.post("/api/certificates", content_type="application/json", json=certificate)
|
|
1004 |
assert ret.status_code == 201
|
|
1005 |
|
|
1006 |
def test_create_with_key_no_pass_invalid_1(server, cryptography_service):
|
|
1007 |
certificate = {
|
|
1008 |
"CA": 1,
|
|
1009 |
"subject": {
|
|
1010 |
"C": "CZ",
|
|
1011 |
"CN": "Rare Name",
|
|
1012 |
"L": "Legendary Name",
|
|
1013 |
"O": "Obscure Name",
|
|
1014 |
"OU": "Original Uniform"
|
|
1015 |
},
|
|
1016 |
"usage": ["CA", "digitalSignature"],
|
|
1017 |
"validityDays": 1,
|
|
1018 |
"key": {
|
|
1019 |
"key_pem": "hi im garbage and you better pray `server` survives this"
|
|
1020 |
},
|
|
1021 |
}
|
|
1022 |
ret = server.post("/api/certificates", content_type="application/json", json=certificate)
|
|
1023 |
assert ret.status_code == 400
|
|
1024 |
assert not ret.json["success"]
|
|
1025 |
|
|
1026 |
def test_create_no_key_with_pass(server, cryptography_service):
|
|
1027 |
key_pass = "123456Seven"
|
|
1028 |
|
|
1029 |
certificate = {
|
|
1030 |
"CA": 1,
|
|
1031 |
"subject": {
|
|
1032 |
"C": "CZ",
|
|
1033 |
"CN": "Rare Name",
|
|
1034 |
"L": "Legendary Name",
|
|
1035 |
"O": "Obscure Name",
|
|
1036 |
"OU": "Original Uniform"
|
|
1037 |
},
|
|
1038 |
"usage": ["CA", "digitalSignature"],
|
|
1039 |
"validityDays": 1,
|
|
1040 |
"key": {
|
|
1041 |
"password": key_pass,
|
|
1042 |
},
|
|
1043 |
}
|
|
1044 |
ret = server.post("/api/certificates", content_type="application/json", json=certificate)
|
|
1045 |
assert ret.status_code == 201
|
|
1046 |
assert ret.json["success"]
|
|
1047 |
created_id = ret.json["data"]
|
|
1048 |
ret = server.get(f"/api/certificates/{created_id}/privatekey")
|
|
1049 |
assert ret.status_code == 200
|
|
1050 |
assert ret.json["success"]
|
|
1051 |
key_pem = ret.json["data"]
|
|
1052 |
assert cryptography_service.verify_key(key_pem, key_pass)
|
|
1053 |
|
|
1054 |
def test_create_no_key_with_pass_invalid_1(server, cryptography_service):
|
|
1055 |
key_pass = "123456Seven"
|
|
1056 |
|
|
1057 |
certificate = {
|
|
1058 |
"CA": 1,
|
|
1059 |
"subject": {
|
|
1060 |
"C": "CZ",
|
|
1061 |
"CN": "Rare Name",
|
|
1062 |
"L": "Legendary Name",
|
|
1063 |
"O": "Obscure Name",
|
|
1064 |
"OU": "Original Uniform"
|
|
1065 |
},
|
|
1066 |
"usage": ["CA", "digitalSignature"],
|
|
1067 |
"validityDays": 1,
|
|
1068 |
"key": {
|
|
1069 |
"password": key_pass,
|
|
1070 |
},
|
|
1071 |
}
|
|
1072 |
ret = server.post("/api/certificates", content_type="application/json", json=certificate)
|
|
1073 |
assert ret.status_code == 201
|
|
1074 |
assert ret.json["success"]
|
|
1075 |
created_id = ret.json["data"]
|
|
1076 |
ret = server.get(f"/api/certificates/{created_id}/privatekey")
|
|
1077 |
assert ret.status_code == 200
|
|
1078 |
assert ret.json["success"]
|
|
1079 |
key_pem = ret.json["data"]
|
|
1080 |
assert not cryptography_service.verify_key(key_pem, "iforgotthepassagainimsorryfrowningface")
|
|
1081 |
|
|
1082 |
def test_create_no_key_no_pass_invalid(server, cryptography_service):
|
|
1083 |
certificate = {
|
|
1084 |
"CA": 1,
|
|
1085 |
"subject": {
|
|
1086 |
"C": "CZ",
|
|
1087 |
"CN": "Rare Name",
|
|
1088 |
"L": "Legendary Name",
|
|
1089 |
"O": "Obscure Name",
|
|
1090 |
"OU": "Original Uniform"
|
|
1091 |
},
|
|
1092 |
"usage": ["CA", "digitalSignature"],
|
|
1093 |
"validityDays": 1,
|
|
1094 |
"key": {
|
|
1095 |
}
|
|
1096 |
}
|
|
1097 |
ret = server.post("/api/certificates", content_type="application/json", json=certificate)
|
|
1098 |
assert ret.status_code == 201 # TODO Honza? CertificateController/create_cert
|
|
1099 |
|
|
1100 |
def test_key_reusal(server, cryptography_service):
|
|
1101 |
# key_pass = "1234567Eight"
|
|
1102 |
# key_pem = cryptography_service.create_private_key(key_pass)
|
|
1103 |
#
|
|
1104 |
# certificate = {
|
|
1105 |
# "CA": 1,
|
|
1106 |
# "subject": {
|
|
1107 |
# "C": "CZ",
|
|
1108 |
# "CN": "Rare Name",
|
|
1109 |
# "L": "Legendary awd",
|
|
1110 |
# "O": "Obscure awd",
|
|
1111 |
# "OU": "Original Uniform"
|
|
1112 |
# },
|
|
1113 |
# "usage": ["CA", "digitalSignature"],
|
|
1114 |
# "validityDays": 1,
|
|
1115 |
# "key": {
|
|
1116 |
# "password": key_pass,
|
|
1117 |
# "key_pem": key_pem
|
|
1118 |
# },
|
|
1119 |
# }
|
|
1120 |
# ret = server.post("/api/certificates", content_type="application/json", json=certificate)
|
|
1121 |
# assert ret.staus_code == 201
|
|
1122 |
# assert ret.json["success"]
|
|
1123 |
# created_id = ret.json["data"]
|
|
1124 |
# ret = server.get(f"/api/certificates/{created_id}/privatekey")
|
|
1125 |
# assert ret.status_code == 200
|
|
1126 |
# assert ret.json["success"]
|
|
1127 |
# key_pem = ret.json["data"]
|
|
1128 |
# TODO
|
|
1129 |
pass
|
Re #8705 - Added tests, changed usages (dict -> list).