Skip to content

Commit 9d6131a

Browse files
authored
fix IP address value in cert meta data (#1187)
1 parent 0df3f7d commit 9d6131a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pkg/files/file_helpers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func FileMetaWithCertificate(filePath string) (*mpi.FileMeta, error) {
8989
},
9090
Sans: &mpi.SubjectAlternativeNames{
9191
DnsNames: loadedCert.DNSNames,
92-
IpAddresses: convertIPBytes(loadedCert.IPAddresses),
92+
IpAddresses: convertIPToString(loadedCert.IPAddresses),
9393
},
9494
Dates: &mpi.CertificateDates{
9595
NotBefore: loadedCert.NotBefore.Unix(),
@@ -153,14 +153,14 @@ func ConvertToMapOfFiles(files []*mpi.File) map[string]*mpi.File {
153153
return filesMap
154154
}
155155

156-
func convertIPBytes(ips []net.IP) []string {
157-
stringArray := make([]string, len(ips))
156+
func convertIPToString(ips []net.IP) []string {
157+
ipArray := make([]string, len(ips))
158158

159-
for i, byteArray := range ips {
160-
stringArray[i] = string(byteArray)
159+
for i, ip := range ips {
160+
ipArray[i] = ip.String()
161161
}
162162

163-
return stringArray
163+
return ipArray
164164
}
165165

166166
func convertX509SignatureAlgorithm(alg x509.SignatureAlgorithm) mpi.SignatureAlgorithm {

pkg/files/file_helpers_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,21 @@ func TestGenerateHash(t *testing.T) {
168168
}
169169
}
170170

171-
func TestConvertIpBytes(t *testing.T) {
171+
func TestConvertIpToString(t *testing.T) {
172172
tests := []struct {
173173
input []net.IP
174174
expected []string
175175
}{
176176
{
177177
input: []net.IP{net.IPv4(192, 168, 0, 1), net.IPv4(10, 0, 0, 1)},
178178
expected: []string{
179-
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xc0\xa8\x00\x01",
180-
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\n\x00\x00\x01",
179+
"192.168.0.1",
180+
"10.0.0.1",
181181
},
182182
},
183183
{
184184
input: []net.IP{net.ParseIP("2001:0db8::68")},
185-
expected: []string{" \x01\r\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00h"},
185+
expected: []string{"2001:db8::68"},
186186
},
187187
{
188188
input: []net.IP{},
@@ -191,7 +191,7 @@ func TestConvertIpBytes(t *testing.T) {
191191
}
192192

193193
for _, test := range tests {
194-
result := convertIPBytes(test.input)
194+
result := convertIPToString(test.input)
195195
for i := range result {
196196
assert.Equal(t, test.expected[i], result[i])
197197
}

0 commit comments

Comments
 (0)