1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# Copyright 2014 Microsoft Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Requires Python 2.4+ and Openssl 1.0+
#
# Implements parts of RFC 2131, 1541, 1497 and
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
import tests.env
from .tools import *
import uuid
import unittest
import os
import json
import azurelinuxagent.utils.fileutil as fileutil
import azurelinuxagent.protocol.v1 as v1
certs_sample=u"""\
<?xml version="1.0" encoding="utf-8"?>
<CertificateFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="certificates10.xsd">
<Version>2012-11-30</Version>
<Incarnation>12</Incarnation>
<Format>Pkcs7BlobWithPfxContents</Format>
<Data>MIINswYJKoZIhvcNAQcDoIINpDCCDaACAQIxggEwMIIBLAIBAoAUvyL+x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/fuM4UPlR5mN+bypU
-----END PRIVATE KEY-----
"""
def MockGetOpensslCmd():
return 'openssl'
class TestCertificates(unittest.TestCase):
def test_certificates(self):
crt1 = '/tmp/33B0ABCE4673538650971C10F7D7397E71561F35.crt'
crt2 = '/tmp/4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3.crt'
prv2 = '/tmp/4037FBF5F1F3014F99B5D6C7799E9B20E6871CB3.prv'
os.chdir('/tmp')
if os.path.isfile(crt1):
os.remove(crt1)
if os.path.isfile(crt2):
os.remove(crt2)
if os.path.isfile(prv2):
os.remove(prv2)
fileutil.write_file(os.path.join('/tmp', "TransportCert.pem"),
transport_cert)
fileutil.write_file(os.path.join('/tmp', "TransportPrivate.pem"),
transport_private)
config = v1.Certificates(certs_sample)
self.assertNotEquals(None, config)
self.assertTrue(os.path.isfile(crt1))
self.assertTrue(os.path.isfile(crt2))
self.assertTrue(os.path.isfile(prv2))
self.assertNotEquals(0, len(config.cert_list.certificates))
cert = config.cert_list.certificates[0]
self.assertNotEquals(None, cert.thumbprint)
if __name__ == '__main__':
unittest.main()
|