diff --git a/pkg/wsman/amt/publickey/certificate.go b/pkg/wsman/amt/publickey/certificate.go index b0fe20fb..49f6b357 100644 --- a/pkg/wsman/amt/publickey/certificate.go +++ b/pkg/wsman/amt/publickey/certificate.go @@ -75,23 +75,43 @@ func (certificate Certificate) Enumerate() (response Response, err error) { // Pull returns the instances of this class. An enumeration context provided by the Enumerate call is used as input. func (certificate Certificate) Pull(enumerationContext string) (response Response, err error) { + var refinedOutput []RefinedPublicKeyCertificateResponse + response = Response{ Message: &client.Message{ XMLInput: certificate.base.Pull(enumerationContext), }, } + // send the message to AMT err = certificate.base.Execute(response.Message) if err != nil { - return + return response, err } + // put the xml response into the go struct err = xml.Unmarshal([]byte(response.XMLOutput), &response) if err != nil { - return + return response, err } - return + for _, item := range response.Body.PullResponse.PublicKeyCertificateItems { + output := RefinedPublicKeyCertificateResponse{ + InstanceID: item.InstanceID, + X509Certificate: item.X509Certificate, + ElementName: item.ElementName, + TrustedRootCertificate: item.TrustedRootCertificate, + Issuer: item.Issuer, + Subject: item.Subject, + ReadOnlyCertificate: item.ReadOnlyCertificate, + } + + refinedOutput = append(refinedOutput, output) + } + + response.Body.RefinedPullResponse.PublicKeyCertificateItems = refinedOutput + + return response, err } // Put will change properties of the selected instance. diff --git a/pkg/wsman/amt/publickey/certificate_test.go b/pkg/wsman/amt/publickey/certificate_test.go index b9617fa3..f66f310e 100644 --- a/pkg/wsman/amt/publickey/certificate_test.go +++ b/pkg/wsman/amt/publickey/certificate_test.go @@ -26,7 +26,7 @@ func TestJson(t *testing.T) { AddCertificate_OUTPUT: AddCertificate_OUTPUT{}, }, } - expectedResult := "{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"AddTrustedRootCertificate_OUTPUT\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"CreatedCertificate\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Address\":\"\",\"ReferenceParameters\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"ResourceURI\":\"\",\"SelectorSet\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Selectors\":null}}},\"ReturnValue\":0},\"AddCertificate_OUTPUT\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"CreatedCertificate\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Address\":\"\",\"ReferenceParameters\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"ResourceURI\":\"\",\"SelectorSet\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Selectors\":null}}},\"ReturnValue\":0},\"AddKey_OUTPUT\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"CreatedKey\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Address\":\"\",\"ReferenceParameters\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"ResourceURI\":\"\",\"SelectorSet\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Selectors\":null}}},\"ReturnValue\":0},\"GenerateKeyPair_OUTPUT\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"KeyPair\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Address\":\"\",\"ReferenceParameters\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"ResourceURI\":\"\",\"SelectorSet\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Selectors\":null}}},\"ReturnValue\":0},\"GeneratePKCS10RequestEx_OUTPUT\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"SignedCertificateRequest\":\"\",\"ReturnValue\":0},\"KeyManagementGetResponse\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"CreationClassName\":\"\",\"ElementName\":\"\",\"EnabledDefault\":0,\"EnabledState\":0,\"Name\":\"\",\"OperationalStatus\":null,\"RequestedState\":0,\"SystemCreationClassName\":\"\",\"SystemName\":\"\"},\"PublicKeyCertificateGetAndPutResponse\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"ElementName\":\"\",\"InstanceID\":\"\",\"X509Certificate\":\"\",\"TrustedRootCertificate\":false,\"Issuer\":\"\",\"Subject\":\"\",\"ReadOnlyCertificate\":false},\"EnumerateResponse\":{\"EnumerationContext\":\"\"},\"PullResponse\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"KeyManagementItems\":null,\"PublicKeyCertificateItems\":null}}" + expectedResult := "{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"AddTrustedRootCertificate_OUTPUT\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"CreatedCertificate\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Address\":\"\",\"ReferenceParameters\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"ResourceURI\":\"\",\"SelectorSet\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Selectors\":null}}},\"ReturnValue\":0},\"AddCertificate_OUTPUT\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"CreatedCertificate\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Address\":\"\",\"ReferenceParameters\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"ResourceURI\":\"\",\"SelectorSet\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Selectors\":null}}},\"ReturnValue\":0},\"AddKey_OUTPUT\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"CreatedKey\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Address\":\"\",\"ReferenceParameters\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"ResourceURI\":\"\",\"SelectorSet\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Selectors\":null}}},\"ReturnValue\":0},\"GenerateKeyPair_OUTPUT\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"KeyPair\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Address\":\"\",\"ReferenceParameters\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"ResourceURI\":\"\",\"SelectorSet\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"Selectors\":null}}},\"ReturnValue\":0},\"GeneratePKCS10RequestEx_OUTPUT\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"SignedCertificateRequest\":\"\",\"ReturnValue\":0},\"KeyManagementGetResponse\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"CreationClassName\":\"\",\"ElementName\":\"\",\"EnabledDefault\":0,\"EnabledState\":0,\"Name\":\"\",\"OperationalStatus\":null,\"RequestedState\":0,\"SystemCreationClassName\":\"\",\"SystemName\":\"\"},\"PublicKeyCertificateGetAndPutResponse\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"ElementName\":\"\",\"InstanceID\":\"\",\"X509Certificate\":\"\",\"TrustedRootCertificate\":false,\"Issuer\":\"\",\"Subject\":\"\",\"ReadOnlyCertificate\":false},\"EnumerateResponse\":{\"EnumerationContext\":\"\"},\"PullResponse\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"KeyManagementItems\":null,\"PublicKeyCertificateItems\":null},\"RefinedPullResponse\":{}}" result := response.JSON() assert.Equal(t, expectedResult, result) } @@ -37,7 +37,7 @@ func TestYaml(t *testing.T) { AddCertificate_OUTPUT: AddCertificate_OUTPUT{}, }, } - expectedResult := "xmlname:\n space: \"\"\n local: \"\"\naddtrustedrootcertificate_output:\n xmlname:\n space: \"\"\n local: \"\"\n createdcertificate:\n xmlname:\n space: \"\"\n local: \"\"\n address: \"\"\n referenceparameters:\n xmlname:\n space: \"\"\n local: \"\"\n resourceuri: \"\"\n selectorset:\n xmlname:\n space: \"\"\n local: \"\"\n selectors: []\n returnvalue: 0\naddcertificate_output:\n xmlname:\n space: \"\"\n local: \"\"\n createdcertificate:\n xmlname:\n space: \"\"\n local: \"\"\n address: \"\"\n referenceparameters:\n xmlname:\n space: \"\"\n local: \"\"\n resourceuri: \"\"\n selectorset:\n xmlname:\n space: \"\"\n local: \"\"\n selectors: []\n returnvalue: 0\naddkey_output:\n xmlname:\n space: \"\"\n local: \"\"\n createdkey:\n xmlname:\n space: \"\"\n local: \"\"\n address: \"\"\n referenceparameters:\n xmlname:\n space: \"\"\n local: \"\"\n resourceuri: \"\"\n selectorset:\n xmlname:\n space: \"\"\n local: \"\"\n selectors: []\n returnvalue: 0\ngeneratekeypair_output:\n xmlname:\n space: \"\"\n local: \"\"\n keypair:\n xmlname:\n space: \"\"\n local: \"\"\n address: \"\"\n referenceparameters:\n xmlname:\n space: \"\"\n local: \"\"\n resourceuri: \"\"\n selectorset:\n xmlname:\n space: \"\"\n local: \"\"\n selectors: []\n returnvalue: 0\ngeneratepkcs10requestex_output:\n xmlname:\n space: \"\"\n local: \"\"\n signedcertificaterequest: \"\"\n returnvalue: 0\nkeymanagementgetresponse:\n xmlname:\n space: \"\"\n local: \"\"\n creationclassname: \"\"\n elementname: \"\"\n enableddefault: 0\n enabledstate: 0\n name: \"\"\n operationalstatus: []\n requestedstate: 0\n systemcreationclassname: \"\"\n systemname: \"\"\npublickeycertificategetandputresponse:\n xmlname:\n space: \"\"\n local: \"\"\n elementname: \"\"\n instanceid: \"\"\n x509certificate: \"\"\n trustedrootcertificate: false\n issuer: \"\"\n subject: \"\"\n readonlycertificate: false\nenumerateresponse:\n enumerationcontext: \"\"\npullresponse:\n xmlname:\n space: \"\"\n local: \"\"\n keymanagementitems: []\n publickeycertificateitems: []\n" + expectedResult := "xmlname:\n space: \"\"\n local: \"\"\naddtrustedrootcertificate_output:\n xmlname:\n space: \"\"\n local: \"\"\n createdcertificate:\n xmlname:\n space: \"\"\n local: \"\"\n address: \"\"\n referenceparameters:\n xmlname:\n space: \"\"\n local: \"\"\n resourceuri: \"\"\n selectorset:\n xmlname:\n space: \"\"\n local: \"\"\n selectors: []\n returnvalue: 0\naddcertificate_output:\n xmlname:\n space: \"\"\n local: \"\"\n createdcertificate:\n xmlname:\n space: \"\"\n local: \"\"\n address: \"\"\n referenceparameters:\n xmlname:\n space: \"\"\n local: \"\"\n resourceuri: \"\"\n selectorset:\n xmlname:\n space: \"\"\n local: \"\"\n selectors: []\n returnvalue: 0\naddkey_output:\n xmlname:\n space: \"\"\n local: \"\"\n createdkey:\n xmlname:\n space: \"\"\n local: \"\"\n address: \"\"\n referenceparameters:\n xmlname:\n space: \"\"\n local: \"\"\n resourceuri: \"\"\n selectorset:\n xmlname:\n space: \"\"\n local: \"\"\n selectors: []\n returnvalue: 0\ngeneratekeypair_output:\n xmlname:\n space: \"\"\n local: \"\"\n keypair:\n xmlname:\n space: \"\"\n local: \"\"\n address: \"\"\n referenceparameters:\n xmlname:\n space: \"\"\n local: \"\"\n resourceuri: \"\"\n selectorset:\n xmlname:\n space: \"\"\n local: \"\"\n selectors: []\n returnvalue: 0\ngeneratepkcs10requestex_output:\n xmlname:\n space: \"\"\n local: \"\"\n signedcertificaterequest: \"\"\n returnvalue: 0\nkeymanagementgetresponse:\n xmlname:\n space: \"\"\n local: \"\"\n creationclassname: \"\"\n elementname: \"\"\n enableddefault: 0\n enabledstate: 0\n name: \"\"\n operationalstatus: []\n requestedstate: 0\n systemcreationclassname: \"\"\n systemname: \"\"\npublickeycertificategetandputresponse:\n xmlname:\n space: \"\"\n local: \"\"\n elementname: \"\"\n instanceid: \"\"\n x509certificate: \"\"\n trustedrootcertificate: false\n issuer: \"\"\n subject: \"\"\n readonlycertificate: false\nenumerateresponse:\n enumerationcontext: \"\"\npullresponse:\n xmlname:\n space: \"\"\n local: \"\"\n keymanagementitems: []\n publickeycertificateitems: []\nrefinedpullresponse:\n keymanagementitems: []\n publickeycertificateitems: []\n" result := response.YAML() assert.Equal(t, expectedResult, result) } @@ -154,6 +154,40 @@ func TestPositiveAMT_PublicKeyCertificate(t *testing.T) { }, }, }, + RefinedPullResponse: RefinedPullResponse{ + PublicKeyCertificateItems: []RefinedPublicKeyCertificateResponse{ + { + ElementName: "Intel(r) AMT Certificate", + InstanceID: "Intel(r) AMT Certificate: Handle: 0", + Issuer: "C=unknown,O=unknown,CN=MPSRoot-0af1d5", + Subject: "C=unknown,O=unknown,CN=MPSRoot-0af1d5", + TrustedRootCertificate: true, + X509Certificate: X509TestCertificate, + PublicKeyHandle: "", + AssociatedProfiles: nil, + }, + { + ElementName: "Intel(r) AMT Certificate", + InstanceID: "Intel(r) AMT Certificate: Handle: 1", + Issuer: "C=unknown,O=unknown,CN=MPSRoot-0af1d5", + Subject: "C=unknown,O=unknown,CN=MPSRoot-0af1d5", + TrustedRootCertificate: false, + X509Certificate: "MIIEOzCCAqOgAwIBAgIDAZMjMA0GCSqGSIb3DQEBDAUAMD0xFzAVBgNVBAMTDk1QU1Jvb3QtMGFmMWQ1MRAwDgYDVQQKEwd1bmtub3duMRAwDgYDVQQGEwd1bmtub3duMCAXDTIyMDkyNDEwNDUwOFoYDzIwNTMwOTI0MTA0NTA4WjA9MRcwFQYDVQQDEw5NUFNSb290LTBhZjFkNTEQMA4GA1UEChMHdW5rbm93bjEQMA4GA1UEBhMHdW5rbm93bjCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALz/oJNyWXlClSlteAieC8Uyd4A+tbn8b45k6LKiImhDmdz/xFo9xe0C9GNf7b42KVpg5WoH/sPhoClR9Tv5i1LnilT1SUir42fcm2NEV9dRcLsPd/RAQfz8u0D4zb3blnxE8isqzriNpG7kac35UidSr5ym8TZ3IwXx6JJuncGgfB0DFZADC/+dA74n3coykvWBYqLr6RI5pkAxvulkRlCsatJTJrvMUYJ51GI28jV56mIAc89sLrHqiSKCZBH9AcUrnZ/cB6ST/IikXpxy5wXBIvWT3VKVq75T/uIoCBEp5TLEn1EOYGqBBOCSQgmtmX7eVaB0s1+ppPW9w9a2zS45cHAtQ7tYvkkPv2dRhSzZdlk6HRXDP5wsF0aiflZCgbrjkq0SFC4e3Lo7XQX3FTNb0SOTZVTydupoMKkgJQTNlcosdu1ZzaIBl3eSkKkJZz2rUTssZC5tn9vcDd5vy3BzcGh5pvkgfAgN1sydqG7Ke1qCkNEzm11B/BsevatjjwIDAQABo0IwQDAMBgNVHRMEBTADAQH/MBEGCWCGSAGG+EIBAQQEAwIABzAdBgNVHQ4EFgQUCvHVQqerCid99eLApuLky9x6H5owDQYJKoZIhvcNAQEMBQADggGBAIzOyGV0hzsmH2biJlzwTZaHMxqS7boTFMkHw+KvzsI201tHqVmCoiQ8EHErBGLSoDOTDRgOUGOCA5XU5ie9OWupAGqKBSwIyAhmJMOzrzC4Gwpu8K1msoFJH30kx/V9purpbS3BRj0xfYXLa6IczbTg3E5IfTnZRJ9YuUtKQfI0P9c5U9CoKtddKn4+lRvOjFDoYfQGCJ7go3xjNCcGCVCjfkUhAVdbQ21DCRr6/YCZDWmjzZpL0p7UKF8roTiNuL/Z7gIXxch5HOmEWHY9uQ6K2MntuxAu0aK/mSD2kwmt/ECongdEGfUvhULLoPRQlQ2LnzcUQEgMECGQR5Yfy9jT0E8zdWDpc2tgVioNu6rEYKgp/GhG+sv7jv58pW82FRAV9xXtftW9+XDugC8tBJ6JHn0Q2v0QAflD2CEQVhWAY8bAqrbfTGUsaLfGL6kxV/qqssoMgLR8Whq96T5le/4XGhQpbCHWIlctD6MwbrsunIAeQKp1Sc3DosY7DLq1MQ==", + PublicKeyHandle: "", + AssociatedProfiles: nil, + }, + { + ElementName: "Intel(r) AMT Certificate", + InstanceID: "Intel(r) AMT Certificate: Handle: 2", + Issuer: "C=unknown,O=unknown,CN=MPSRoot-0af1d5", + Subject: "C=unknown,O=unknown,CN=MPSRoot-0af1d5", + TrustedRootCertificate: true, + X509Certificate: "MIIEOzCCAqOgAwIBAgIDAZMjMA0GCSqGSIb3DQEBDAUAMD0xFzAVBgNVBAMTDk1QU1Jvb3QtMGFmMWQ1MRAwDgYDVQQKEwd1bmtub3duMRAwDgYDVQQGEwd1bmtub3duMCAXDTIyMDkyNDEwNDUwOFoYDzIwNTMwOTI0MTA0NTA4WjA9MRcwFQYDVQQDEw5NUFNSb290LTBhZjFkNTEQMA4GA1UEChMHdW5rbm93bjEQMA4GA1UEBhMHdW5rbm93bjCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALz/oJNyWXlClSlteAieC8Uyd4A+tbn8b45k6LKiImhDmdz/xFo9xe0C9GNf7b42KVpg5WoH/sPhoClR9Tv5i1LnilT1SUir42fcm2NEV9dRcLsPd/RAQfz8u0D4zb3blnxE8isqzriNpG7kac35UidSr5ym8TZ3IwXx6JJuncGgfB0DFBADC/+dA74n3coykvWBYqLr6RI5pkAxvulkRlCsatJTJrvMUYJ51GI28jV56mIAc89sLrHqiSKCZBH9AcUrnZ/cB6ST/IikXpxy5wXBIvWT3VKVq75T/uIoCBEp5TLEn1EOYGqBBOCSQgmtmX7eVaB0s1+ppPW9w9a2zS45cHAtQ7tYvkkPv2dRhSzZdlk6HRXDP5wsF0aiflZCgbrjkq0SFC4e3Lo7XQX3FTNb0SOTZVTydupoMKkgJQTNlcosdu1ZzaIBl3eSkKkJZz2rUTssZC5tn9vcDd5vy3BzcGh5pvkgfAgN1sydqG7Ke1qCkNEzm11B/BsevatjjwIDAQABo0IwQDAMBgNVHRMEBTADAQH/MBEGCWCGSAGG+EIBAQQEAwIABzAdBgNVHQ4EFgQUCvHVQqerCid99eLApuLky9x6H5owDQYJKoZIhvcNAQEMBQADggGBAIzOyGV0hzsmH2biJlzwTZaHMxqS7boTFMkHw+KvzsI201tHqVmCoiQ8EHErBGLSoDOTDRgOUGOCA5XU5ie9OWupAGqKBSwIyAhmJMOzrzC4Gwpu8K1msoFJH30kx/V9purpbS3BRj0xfYXLa6IczbTg3E5IfTnZRJ9YuUtKQfI0P9c5U9CoKtddKn4+lRvOjFDoYfQGCJ7go3xjNCcGCVCjfkUhAVdbQ21DCRr6/YCZDWmjzZpL0p7UKF8roTiNuL/Z7gIXxch5HOmEWHY9uQ6K2MntuxAu0aK/mSD2kwmt/ECongdEGfUvhULLoPRQlQ2LnzcUQEgMECGQR5Yfy9jT0E8zdWDpc2tgVioNu6rEYKgp/GhG+sv7jv58pW82FRAV9xXtftW9+XDugC8tBJ6JHn0Q2v0QAflD2CEQVhWAY8bAqrbfTGUsaLfGL6kxV/qqssoMgLR8Whq96T5le/4XGhQpbCHWIlctD6MwbrsunIAeQKp1Sc3DosY7DLq1MQ==", + PublicKeyHandle: "", + AssociatedProfiles: nil, + }, + }, + }, }, }, diff --git a/pkg/wsman/amt/publickey/types.go b/pkg/wsman/amt/publickey/types.go index 6d6c6ec7..bd9b2ca3 100644 --- a/pkg/wsman/amt/publickey/types.go +++ b/pkg/wsman/amt/publickey/types.go @@ -41,6 +41,11 @@ type ( PublicKeyCertificateGetAndPutResponse PublicKeyCertificateResponse `xml:"AMT_PublicKeyCertificate,omitempty"` EnumerateResponse common.EnumerateResponse PullResponse PullResponse + RefinedPullResponse RefinedPullResponse + } + RefinedPullResponse struct { + KeyManagementItems []RefinedKeyManagementResponse `json:"KeyManagementItems,omitempty"` + PublicKeyCertificateItems []RefinedPublicKeyCertificateResponse `json:"PublicKeyCertificateItems,omitempty"` } PullResponse struct { XMLName xml.Name `xml:"PullResponse,omitempty"` @@ -59,6 +64,17 @@ type ( SystemCreationClassName string `xml:"SystemCreationClassName,omitempty"` // The CreationClassName of the scoping System. SystemName string `xml:"SystemName,omitempty"` // The Name of the scoping System. } + RefinedKeyManagementResponse struct { + CreationClassName string + ElementName string + EnabledDefault EnabledDefault + EnabledState EnabledState + Name string + RequestedState RequestedState + SystemCreationClassName string + SystemName string + } + PublicKeyCertificateResponse struct { XMLName xml.Name `xml:"AMT_PublicKeyCertificate,omitempty"` ElementName string `xml:"ElementName,omitempty"` // A user-friendly name for the object . . . @@ -69,6 +85,18 @@ type ( Subject string `xml:"Subject,omitempty"` // The Subject field of this certificate. ReadOnlyCertificate bool `xml:"ReadOnlyCertificate"` // Indicates whether the certificate is an Intel AMT self-signed certificate. If True, the certificate cannot be deleted. } + + RefinedPublicKeyCertificateResponse struct { + ElementName string `json:"ElementName,omitempty"` // A user-friendly name for the object . . . + InstanceID string `json:"InstanceID,omitempty"` // Within the scope of the instantiating Namespace, InstanceID opaquely and uniquely identifies an instance of this class. + X509Certificate string `json:"X509Certificate,omitempty"` // uint8[4100] // The X.509 Certificate blob. + TrustedRootCertificate bool `json:"TrustedRootCertficate"` // For root certificate [that were added by AMT_PublicKeyManagementService.AddTrustedRootCertificate()]this property will be true. FYI Certificate is spelled wrong comimg from AMT. + Issuer string `json:"Issuer,omitempty"` // The Issuer field of this certificate. + Subject string `json:"Subject,omitempty"` // The Subject field of this certificate. + ReadOnlyCertificate bool `json:"ReadOnlyCertificate"` // Indicates whether the certificate is an Intel AMT self-signed certificate. If True, the certificate cannot be deleted. + PublicKeyHandle string `json:"PublicKeyHandle,omitempty"` + AssociatedProfiles []string `json:"AssociatedProfiles,omitempty"` + } AddTrustedRootCertificate_OUTPUT struct { XMLName xml.Name `xml:"AddTrustedRootCertificate_OUTPUT"` CreatedCertificate CreatedCertificateResponse `xml:"CreatedCertificate,omitempty"` diff --git a/pkg/wsman/amt/publicprivate/keypair.go b/pkg/wsman/amt/publicprivate/keypair.go index 7c8408b6..7b2e8a9c 100644 --- a/pkg/wsman/amt/publicprivate/keypair.go +++ b/pkg/wsman/amt/publicprivate/keypair.go @@ -70,23 +70,39 @@ func (keyPair KeyPair) Enumerate() (response Response, err error) { // Pull returns the instances of this class. An enumeration context provided by the Enumerate call is used as input. func (keyPair KeyPair) Pull(enumerationContext string) (response Response, err error) { + var refinedOutput []RefinedPublicPrivateKeyPair + response = Response{ Message: &client.Message{ XMLInput: keyPair.base.Pull(enumerationContext), }, } + // send the message to AMT err = keyPair.base.Execute(response.Message) if err != nil { - return + return response, err } + // put the xml response into the go struct err = xml.Unmarshal([]byte(response.XMLOutput), &response) if err != nil { - return + return response, err } - return + for _, item := range response.Body.PullResponse.PublicPrivateKeyPairItems { + output := RefinedPublicPrivateKeyPair{ + InstanceID: item.InstanceID, + ElementName: item.ElementName, + DERKey: item.DERKey, + } + + refinedOutput = append(refinedOutput, output) + } + + response.Body.RefinedPullResponse.PublicPrivateKeyPairItems = refinedOutput + + return response, err } // Deletes an instance of a key pair. diff --git a/pkg/wsman/amt/publicprivate/keypair_test.go b/pkg/wsman/amt/publicprivate/keypair_test.go index a13cc2cd..5a7ed627 100644 --- a/pkg/wsman/amt/publicprivate/keypair_test.go +++ b/pkg/wsman/amt/publicprivate/keypair_test.go @@ -23,7 +23,7 @@ func TestJson(t *testing.T) { GetResponse: PublicPrivateKeyPair{}, }, } - expectedResult := "{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"GetResponse\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"ElementName\":\"\",\"InstanceID\":\"\",\"DERKey\":\"\"},\"EnumerateResponse\":{\"EnumerationContext\":\"\"},\"PullResponse\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"PublicPrivateKeyPairItems\":null}}" + expectedResult := "{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"GetResponse\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"ElementName\":\"\",\"InstanceID\":\"\",\"DERKey\":\"\"},\"EnumerateResponse\":{\"EnumerationContext\":\"\"},\"PullResponse\":{\"XMLName\":{\"Space\":\"\",\"Local\":\"\"},\"PublicPrivateKeyPairItems\":null},\"RefinedPullResponse\":{\"PublicPrivateKeyPairItems\":null}}" result := response.JSON() assert.Equal(t, expectedResult, result) } @@ -34,7 +34,7 @@ func TestYaml(t *testing.T) { GetResponse: PublicPrivateKeyPair{}, }, } - expectedResult := "xmlname:\n space: \"\"\n local: \"\"\ngetresponse:\n xmlname:\n space: \"\"\n local: \"\"\n elementname: \"\"\n instanceid: \"\"\n derkey: \"\"\nenumerateresponse:\n enumerationcontext: \"\"\npullresponse:\n xmlname:\n space: \"\"\n local: \"\"\n publicprivatekeypairitems: []\n" + expectedResult := "xmlname:\n space: \"\"\n local: \"\"\ngetresponse:\n xmlname:\n space: \"\"\n local: \"\"\n elementname: \"\"\n instanceid: \"\"\n derkey: \"\"\nenumerateresponse:\n enumerationcontext: \"\"\npullresponse:\n xmlname:\n space: \"\"\n local: \"\"\n publicprivatekeypairitems: []\nrefinedpullresponse:\n publicprivatekeypairitems: []\n" result := response.YAML() assert.Equal(t, expectedResult, result) } @@ -135,6 +135,22 @@ func TestPositiveAMT_PublicPrivateKeyPair(t *testing.T) { }, }, }, + RefinedPullResponse: RefinedPullResponse{ + PublicPrivateKeyPairItems: []RefinedPublicPrivateKeyPair{ + { + ElementName: "Intel(r) AMT Key", + InstanceID: "Intel(r) AMT Key: Handle: 0", + DERKey: "MIIBCgKCAQEA4y00wezZ1XwsSITMvqeYf61tgfVhlGbBVwq9Au0BaEgofPFCLuWMnKaTnMhUlJEGaeB2y6F8qjId0xMwLtNY6XWhmMoCP0R+ymgClT0treqtYp2zL1QPK1R04KTgF0KZh247oQpPGnB2nIe7PKCjPaY8BfOyBC6eNLeWUVIOA5TLL0gSTuk8y3iaadKo+LoWBaH/WDrIJ21Dzn6yU3zGueA8tphPH7yXaOJuNiijOUYZjVT7J0Ia8qMxUv1CrbfL2+N0lrcCG/E4f0QF1XgoCJnwIHdYaNhWzKVhfh2TTZIxJo8bXngckNOLzdYM35hUq98CxPiMSO8+G7J8RZaobQIDAQAB", + CertificateHandle: "", + }, + { + ElementName: "Intel(r) AMT Key", + InstanceID: "Intel(r) AMT Key: Handle: 1", + DERKey: "MIIBCgKCAQEAvMgYL2FyGuHOVvwYgjABqRlJ8j8LhMo2OCU1HU2WvDN3NoLmjAh2XmBS6ic5IjIc4VtjL7S8ImKP8+PSye9nxf+lv33AqcGsvQFcUuJ5gLTnYzrmqVk6XTcHf1qtvHEmVoykTV6bN7BQx0eTejTjhw3Ro6HZBMyStaTGIKjC9HLQySV6SnFGbrjdNZZoCYsaT8dVetn23npeses9f6dZT5K3IgpA13NcdJioS71uppjIcg8dXpcxA4QKgHLmmELPN9JLbywMvcCuU+xMDceWQlFld9ohmr8NiwgebLyVCh/Q+O+jkQT43snNolyTGLRWQFR4M6DT5fdgXivoFhzMcwIDAQAB", + CertificateHandle: "", + }, + }, + }, }, }, // DELETE diff --git a/pkg/wsman/amt/publicprivate/types.go b/pkg/wsman/amt/publicprivate/types.go index f56c61a2..632c5fa5 100644 --- a/pkg/wsman/amt/publicprivate/types.go +++ b/pkg/wsman/amt/publicprivate/types.go @@ -28,16 +28,20 @@ type ( } Body struct { - XMLName xml.Name `xml:"Body"` - GetResponse PublicPrivateKeyPair - EnumerateResponse common.EnumerateResponse - PullResponse PullResponse + XMLName xml.Name `xml:"Body"` + GetResponse PublicPrivateKeyPair + EnumerateResponse common.EnumerateResponse + PullResponse PullResponse + RefinedPullResponse RefinedPullResponse } PullResponse struct { XMLName xml.Name `xml:"PullResponse"` PublicPrivateKeyPairItems []PublicPrivateKeyPair `xml:"Items>AMT_PublicPrivateKeyPair"` } + RefinedPullResponse struct { + PublicPrivateKeyPairItems []RefinedPublicPrivateKeyPair + } PublicPrivateKeyPair struct { XMLName xml.Name `xml:"AMT_PublicPrivateKeyPair"` @@ -46,5 +50,11 @@ type ( DERKey string // RSA Key encoded as DES PKCS#1. The Exponent (E) is 65537 (0x010001).When this structure is used as an output parameter (GET or PULL method),only the public section of the key is exported. uint8[1210] } + RefinedPublicPrivateKeyPair struct { + ElementName string // A user-friendly name for the object. This property allows each instance to define a user-friendly name in addition to its key properties, identity data, and description information. Note that the Name property of ManagedSystemElement is also defined as a user-friendly name. But, it is often subclassed to be a Key. It is not reasonable that the same property can convey both identity and a user-friendly name, without inconsistencies. Where Name exists and is not a Key (such as for instances of LogicalDevice), the same information can be present in both the Name and ElementName properties. Note that if there is an associated instance of CIM_EnabledLogicalElementCapabilities, restrictions on this properties may exist as defined in ElementNameMask and MaxElementNameLen properties defined in that class. + InstanceID string // Within the scope of the instantiating Namespace, InstanceID opaquely and uniquely identifies an instance of this class. + DERKey string // RSA Key encoded as DES PKCS#1. The Exponent (E) is 65537 (0x010001).When this structure is used as an output parameter (GET or PULL method),only the public section of the key is exported. uint8[1210] + CertificateHandle string `json:"CertificateHandle,omitempty"` + } PublicPrivateSelector message.Selector ) diff --git a/pkg/wsman/cim/credential/context_test.go b/pkg/wsman/cim/credential/context_test.go index 9aa6912c..fdff5b97 100644 --- a/pkg/wsman/cim/credential/context_test.go +++ b/pkg/wsman/cim/credential/context_test.go @@ -129,8 +129,8 @@ func TestPositiveCIMCredentialContext(t *testing.T) { }, }, }, - []CredentialContextTLS(nil), - []CredentialContext8021x(nil), + []CredentialContext(nil), + []CredentialContext(nil), }, EndOfSequence: xml.Name{Space: "http://schemas.xmlsoap.org/ws/2004/09/enumeration", Local: "EndOfSequence"}, }, @@ -235,8 +235,8 @@ func TestNegativeCIMCredentialContext(t *testing.T) { }, }, }, - []CredentialContextTLS(nil), - []CredentialContext8021x(nil), + []CredentialContext(nil), + []CredentialContext(nil), }, EndOfSequence: xml.Name{Space: "http://schemas.xmlsoap.org/ws/2004/09/enumeration", Local: "EndOfSequence"}, }, diff --git a/pkg/wsman/cim/credential/types.go b/pkg/wsman/cim/credential/types.go index b08da4ef..8f0d4972 100644 --- a/pkg/wsman/cim/credential/types.go +++ b/pkg/wsman/cim/credential/types.go @@ -40,20 +40,12 @@ type ( } Items struct { - CredentialContext []CredentialContext `xml:"CIM_CredentialContext"` - CredentialContextTLS []CredentialContextTLS `xml:"AMT_TLSCredentialContext"` - CredentialContext8021x []CredentialContext8021x `xml:"IPS_8021xCredentialContext"` + CredentialContext []CredentialContext `xml:"CIM_CredentialContext"` + CredentialContextTLS []CredentialContext `xml:"AMT_TLSCredentialContext"` + CredentialContext8021x []CredentialContext `xml:"IPS_8021xCredentialContext"` } CredentialContext struct { ElementInContext models.AssociationReference `xml:"ElementInContext"` // A Credential whose context is defined. ElementProvidingContext models.AssociationReference `xml:"ElementProvidingContext"` // The ManagedElement that provides context or scope for the Credential. } - CredentialContextTLS struct { - ElementInContext models.AssociationReference `xml:"ElementInContext"` // A Credential whose context is defined. - ElementProvidingContext models.AssociationReference `xml:"ElementProvidingContext"` // The ManagedElement that provides context or scope for the Credential. - } - CredentialContext8021x struct { - ElementInContext models.AssociationReference `xml:"ElementInContext"` // A Credential whose context is defined. - ElementProvidingContext models.AssociationReference `xml:"ElementProvidingContext"` // The ManagedElement that provides context or scope for the Credential. - } )