From e2e568fa1f57b40b943283670396a4c1987c05ff Mon Sep 17 00:00:00 2001 From: Rick B Date: Fri, 19 Apr 2024 11:42:00 -0700 Subject: [PATCH] fix: use go-wsman-messages v2.2.4 --- go.mod | 2 +- go.sum | 4 +- internal/flags/activate_test.go | 2 +- internal/flags/configure.go | 33 ++--- internal/flags/configure_test.go | 34 ++--- internal/local/amt/wsman.go | 4 +- internal/local/features.go | 12 +- internal/local/lps_test.go | 244 ++++++++++++++++++++----------- internal/local/wifi.go | 3 +- internal/local/wifi_test.go | 8 +- 10 files changed, 203 insertions(+), 143 deletions(-) diff --git a/go.mod b/go.mod index 1a96c32e..1f7d2d9b 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/gorilla/websocket v1.5.1 github.com/hirochachacha/go-smb2 v1.1.0 github.com/ilyakaznacheev/cleanenv v1.5.0 - github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.2.3 + github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.2.4 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 golang.org/x/sys v0.19.0 diff --git a/go.sum b/go.sum index 84fabda1..f45f982f 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,8 @@ github.com/ilyakaznacheev/cleanenv v1.5.0 h1:0VNZXggJE2OYdXE87bfSSwGxeiGt9moSR2l github.com/ilyakaznacheev/cleanenv v1.5.0/go.mod h1:a5aDzaJrLCQZsazHol1w8InnDcOX0OColm64SlIi6gk= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.2.3 h1:iN/X4G6jtzbWs1NRKmxdKDeyGcKXmdREyHP9uYe/4KE= -github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.2.3/go.mod h1:7aSDcTtCGiyD2pjqguDCjqFvI/Lp603FvzypHOen3zk= +github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.2.4 h1:lWNmmG3Es3TdMqZbOKuOUdktHurfIPxu5+vrmUonJDY= +github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.2.4/go.mod h1:7aSDcTtCGiyD2pjqguDCjqFvI/Lp603FvzypHOen3zk= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= diff --git a/internal/flags/activate_test.go b/internal/flags/activate_test.go index 3d5eda38..b9023c5c 100644 --- a/internal/flags/activate_test.go +++ b/internal/flags/activate_test.go @@ -235,7 +235,7 @@ func TestHandleActivateCommandLocal(t *testing.T) { cmdLine: "./rpc activate -local -acm -config ../../config.yaml", wantResult: nil, }, - "should pass wif acm and ACM Settings specified": { + "should pass if acm and ACM Settings specified": { cmdLine: "./rpc activate -local -acm " + " -amtPassword " + trickyPassword + ` -provisioningCert MIIW/gIBAzCCFroGCSqGSIb3DQEHAaCCFqsEghanMIIWozCCBgwGCSqGSIb3DQEHAaCCBf0EggX5MIIF9TCCBfEGCyqGSIb3DQEMCgECoIIE/jCCBPowHAYKKoZIhvc` + diff --git a/internal/flags/configure.go b/internal/flags/configure.go index 2b9a5dc0..d3b54b1e 100644 --- a/internal/flags/configure.go +++ b/internal/flags/configure.go @@ -547,8 +547,8 @@ func (f *Flags) handleAddWifiSettings() error { if wifiCfg.ProfileName != "" { authMethod := wifi.AuthenticationMethod(wifiCfg.AuthenticationMethod) - if authMethod == wifi.AuthenticationMethod_WPA_IEEE8021x || - authMethod == wifi.AuthenticationMethod_WPA2_IEEE8021x { + if authMethod == wifi.AuthenticationMethodWPAIEEE8021x || + authMethod == wifi.AuthenticationMethodWPA2IEEE8021x { // reuse profilename as configuration reference wifiCfg.Ieee8021xProfileName = wifiCfg.ProfileName ieee8021xCfg.ProfileName = wifiCfg.ProfileName @@ -644,7 +644,7 @@ func (f *Flags) promptForSecrets() error { continue } authMethod := wifi.AuthenticationMethod(item.AuthenticationMethod) - if (authMethod == wifi.AuthenticationMethod_WPA_PSK || authMethod == wifi.AuthenticationMethod_WPA2_PSK) && + if (authMethod == wifi.AuthenticationMethodWPAPSK || authMethod == wifi.AuthenticationMethodWPA2PSK) && item.PskPassphrase == "" { err := f.PromptUserInput("Please enter PskPassphrase for "+item.ProfileName+": ", &item.PskPassphrase) if err != nil { @@ -712,16 +712,16 @@ func (f *Flags) verifyWifiConfigurations() error { authenticationMethod := wifi.AuthenticationMethod(cfg.AuthenticationMethod) switch authenticationMethod { - case wifi.AuthenticationMethod_WPA_PSK: + case wifi.AuthenticationMethodWPAPSK: fallthrough - case wifi.AuthenticationMethod_WPA2_PSK: // AuthenticationMethod 4 + case wifi.AuthenticationMethodWPA2PSK: // AuthenticationMethod 4 if cfg.PskPassphrase == "" { log.Error("missing PskPassphrase for config: ", cfg.ProfileName) return utils.MissingOrInvalidConfiguration } - case wifi.AuthenticationMethod_WPA_IEEE8021x: + case wifi.AuthenticationMethodWPAIEEE8021x: fallthrough - case wifi.AuthenticationMethod_WPA2_IEEE8021x: // AuthenticationMethod 7 + case wifi.AuthenticationMethodWPA2IEEE8021x: // AuthenticationMethod 7 if cfg.ProfileName == "" { log.Error("missing ieee8021x profile name") return utils.MissingOrInvalidConfiguration @@ -734,27 +734,21 @@ func (f *Flags) verifyWifiConfigurations() error { if err != nil { return err } - case wifi.AuthenticationMethod_Other: + case wifi.AuthenticationMethodOther: log.Errorf("unsupported AuthenticationMethod_Other (%d) for config: %s", cfg.AuthenticationMethod, cfg.ProfileName) return utils.MissingOrInvalidConfiguration - case wifi.AuthenticationMethod_OpenSystem: + case wifi.AuthenticationMethodOpenSystem: log.Errorf("unsupported AuthenticationMethod_OpenSystem (%d) for config: %s", cfg.AuthenticationMethod, cfg.ProfileName) return utils.MissingOrInvalidConfiguration - case wifi.AuthenticationMethod_SharedKey: + case wifi.AuthenticationMethodSharedKey: log.Errorf("unsupported AuthenticationMethod_SharedKey (%d) for config: %s", cfg.AuthenticationMethod, cfg.ProfileName) return utils.MissingOrInvalidConfiguration - case wifi.AuthenticationMethod_DMTFReserved: - log.Errorf("unsupported AuthenticationMethod_DMTFReserved (%d) for config: %s", cfg.AuthenticationMethod, cfg.ProfileName) - return utils.MissingOrInvalidConfiguration - case wifi.AuthenticationMethod_WPA3_SAE: + case wifi.AuthenticationMethodWPA3SAE: log.Errorf("unsupported AuthenticationMethod_WPA3_SAE (%d) for config: %s", cfg.AuthenticationMethod, cfg.ProfileName) return utils.MissingOrInvalidConfiguration - case wifi.AuthenticationMethod_WPA3_OWE: + case wifi.AuthenticationMethodWPA3OWE: log.Errorf("unsupported AuthenticationMethod_WPA3_OWE (%d) for config: %s", cfg.AuthenticationMethod, cfg.ProfileName) return utils.MissingOrInvalidConfiguration - case wifi.AuthenticationMethod_VendorReserved: - log.Errorf("unsupported AuthenticationMethod_VendorReserved (%d) for config: %s", cfg.AuthenticationMethod, cfg.ProfileName) - return utils.MissingOrInvalidConfiguration default: log.Errorf("invalid AuthenticationMethod_VendorReserved (%d) for config: %s", cfg.AuthenticationMethod, cfg.ProfileName) return utils.MissingOrInvalidConfiguration @@ -776,9 +770,6 @@ func (f *Flags) verifyWifiConfigurations() error { case wifi.EncryptionMethod_None: log.Errorf("unsupported EncryptionMethod_None (%d) for config: %s", cfg.EncryptionMethod, cfg.ProfileName) return utils.MissingOrInvalidConfiguration - case wifi.EncryptionMethod_DMTFReserved: - log.Errorf("unsupported EncryptionMethod_DMTFReserved (%d) for config: %s", cfg.EncryptionMethod, cfg.ProfileName) - return utils.MissingOrInvalidConfiguration default: log.Errorf("invalid EncryptionMethod (%d) for config: %s", cfg.EncryptionMethod, cfg.ProfileName) return utils.MissingOrInvalidConfiguration diff --git a/internal/flags/configure_test.go b/internal/flags/configure_test.go index 5893c939..ceadc8c1 100644 --- a/internal/flags/configure_test.go +++ b/internal/flags/configure_test.go @@ -13,7 +13,6 @@ import ( "strings" "testing" - "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/models" "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/wifi" "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/ips/ieee8021x" @@ -437,7 +436,7 @@ var wifiCfgWPA = config.WifiConfig{ ProfileName: "wifiWPA", SSID: "ssid", Priority: 1, - AuthenticationMethod: int(wifi.AuthenticationMethod_WPA_PSK), + AuthenticationMethod: int(wifi.AuthenticationMethodWPAPSK), EncryptionMethod: int(wifi.EncryptionMethod_TKIP), PskPassphrase: "wifiWPAPassPhrase", } @@ -446,7 +445,7 @@ var wifiCfgWPA2 = config.WifiConfig{ ProfileName: "wifiWPA2", SSID: "ssid", Priority: 2, - AuthenticationMethod: int(wifi.AuthenticationMethod_WPA2_PSK), + AuthenticationMethod: int(wifi.AuthenticationMethodWPA2PSK), EncryptionMethod: int(wifi.EncryptionMethod_CCMP), PskPassphrase: "wifiWPA2PassPhrase", } @@ -455,7 +454,7 @@ var wifiCfgWPA8021xEAPTLS = config.WifiConfig{ ProfileName: "wifiWPA28021x", SSID: "ssid", Priority: 3, - AuthenticationMethod: int(wifi.AuthenticationMethod_WPA_IEEE8021x), + AuthenticationMethod: int(wifi.AuthenticationMethodWPAIEEE8021x), EncryptionMethod: int(wifi.EncryptionMethod_CCMP), Ieee8021xProfileName: "ieee8021xCfgEAPTLS", } @@ -464,7 +463,7 @@ var ieee8021xCfgEAPTLS = config.Ieee8021xConfig{ ProfileName: "ieee8021xCfgEAPTLS", Username: "username", Password: "", - AuthenticationProtocol: int(models.AuthenticationProtocolEAPTLS), + AuthenticationProtocol: int(ieee8021x.AuthenticationProtocolEAPTLS), ClientCert: "clientCert", CACert: "caCert", PrivateKey: "privateKey", @@ -474,7 +473,7 @@ var wifiCfgWPA28021xPEAPv0_EAPMSCHAPv2 = config.WifiConfig{ ProfileName: "wifiWPA28021x", SSID: "ssid", Priority: 4, - AuthenticationMethod: int(wifi.AuthenticationMethod_WPA2_IEEE8021x), + AuthenticationMethod: int(wifi.AuthenticationMethodWPA2IEEE8021x), EncryptionMethod: int(wifi.EncryptionMethod_CCMP), Ieee8021xProfileName: "ieee8021xCfgPEAPv0_EAPMSCHAPv2", } @@ -538,7 +537,7 @@ func TestVerifyWifiConfiguration(t *testing.T) { }) t.Run("expect MissingOrInvalidConfiguration with invalid AuthenticationMethod", func(t *testing.T) { orig := wifiCfgWPA.AuthenticationMethod - wifiCfgWPA.AuthenticationMethod = int(wifi.AuthenticationMethod_DMTFReserved) + wifiCfgWPA.AuthenticationMethod = int(wifi.AuthenticationMethodWPA2IEEE8021x + 99) runVerifyWifiConfiguration(t, utils.MissingOrInvalidConfiguration, []config.WifiConfig{wifiCfgWPA}, []config.Ieee8021xConfig{}) @@ -546,7 +545,7 @@ func TestVerifyWifiConfiguration(t *testing.T) { }) t.Run("expect MissingOrInvalidConfiguration with invalid EncryptionMethod", func(t *testing.T) { orig := wifiCfgWPA.EncryptionMethod - wifiCfgWPA.EncryptionMethod = int(wifi.EncryptionMethod_DMTFReserved) + wifiCfgWPA.EncryptionMethod = int(wifi.EncryptionMethod_None + 99) runVerifyWifiConfiguration(t, utils.MissingOrInvalidConfiguration, []config.WifiConfig{wifiCfgWPA}, []config.Ieee8021xConfig{}) @@ -635,17 +634,17 @@ func TestVerifyMatchingIeee8021xConfig(t *testing.T) { }) t.Run("expect MissingOrInvalidConfiguration if missing PskPassphrase", func(t *testing.T) { f.LocalConfig.Ieee8021xConfigs[0].PrivateKey = "AABBCCDDEEFF" - f.LocalConfig.Ieee8021xConfigs[0].AuthenticationProtocol = int(models.AuthenticationProtocolPEAPv0_EAPMSCHAPv2) + f.LocalConfig.Ieee8021xConfigs[0].AuthenticationProtocol = int(ieee8021x.AuthenticationProtocolPEAPv0_EAPMSCHAPv2) rc := f.verifyMatchingIeee8021xConfig(name) assert.Equal(t, utils.MissingOrInvalidConfiguration, rc) }) t.Run("expect Success", func(t *testing.T) { - f.LocalConfig.Ieee8021xConfigs[0].AuthenticationProtocol = int(models.AuthenticationProtocolEAPTLS) + f.LocalConfig.Ieee8021xConfigs[0].AuthenticationProtocol = int(ieee8021x.AuthenticationProtocolEAPTLS) rc := f.verifyMatchingIeee8021xConfig(name) assert.Equal(t, nil, rc) }) t.Run("expect MissingOrInvalidConfiguration for unsupported AuthenticationProtocolEAPTTLS_MSCHAPv2", func(t *testing.T) { - f.LocalConfig.Ieee8021xConfigs[0].AuthenticationProtocol = int(models.AuthenticationProtocolEAPTTLS_MSCHAPv2) + f.LocalConfig.Ieee8021xConfigs[0].AuthenticationProtocol = int(ieee8021x.AuthenticationProtocolEAPTTLS_MSCHAPv2) rc := f.verifyMatchingIeee8021xConfig(name) assert.Equal(t, utils.MissingOrInvalidConfiguration, rc) }) @@ -706,13 +705,11 @@ func TestInvalidAuthenticationMethods(t *testing.T) { cases := []struct { method wifi.AuthenticationMethod }{ - {method: wifi.AuthenticationMethod_Other}, - {method: wifi.AuthenticationMethod_OpenSystem}, - {method: wifi.AuthenticationMethod_SharedKey}, - {method: wifi.AuthenticationMethod_DMTFReserved}, - {method: wifi.AuthenticationMethod_WPA3_SAE}, - {method: wifi.AuthenticationMethod_WPA3_OWE}, - {method: wifi.AuthenticationMethod_VendorReserved}, + {method: wifi.AuthenticationMethodOther}, + {method: wifi.AuthenticationMethodOpenSystem}, + {method: wifi.AuthenticationMethodSharedKey}, + {method: wifi.AuthenticationMethodWPA3SAE}, + {method: wifi.AuthenticationMethodWPA3OWE}, {method: 599}, } for _, tc := range cases { @@ -734,7 +731,6 @@ func TestInvalidEncryptionMethods(t *testing.T) { {method: wifi.EncryptionMethod_Other}, {method: wifi.EncryptionMethod_WEP}, {method: wifi.EncryptionMethod_None}, - {method: wifi.EncryptionMethod_DMTFReserved}, {method: 599}, } for _, tc := range cases { diff --git a/internal/local/amt/wsman.go b/internal/local/amt/wsman.go index d800376d..3ff76bc4 100644 --- a/internal/local/amt/wsman.go +++ b/internal/local/amt/wsman.go @@ -75,7 +75,7 @@ type WSMANer interface { GeneratePKCS10RequestEx(keyPair, nullSignedCertificateRequest string, signingAlgorithm publickey.SigningAlgorithm) (response publickey.Response, err error) RequestRedirectionStateChange(requestedState redirection.RequestedState) (response redirection.Response, err error) - RequestKVMStateChange(requestedState kvm.KVMRedirectionSAPRequestedStateInputs) (response kvm.Response, err error) + RequestKVMStateChange(requestedState kvm.KVMRedirectionSAPRequestStateChangeInput) (response kvm.Response, err error) PutRedirectionState(requestedState redirection.RedirectionRequest) (response redirection.Response, err error) GetRedirectionService() (response redirection.Response, err error) GetIpsOptInService() (response optin.Response, err error) @@ -346,7 +346,7 @@ func (g *GoWSMANMessages) RequestRedirectionStateChange(requestedState redirecti return g.wsmanMessages.AMT.RedirectionService.RequestStateChange(requestedState) } -func (g *GoWSMANMessages) RequestKVMStateChange(requestedState kvm.KVMRedirectionSAPRequestedStateInputs) (response kvm.Response, err error) { +func (g *GoWSMANMessages) RequestKVMStateChange(requestedState kvm.KVMRedirectionSAPRequestStateChangeInput) (response kvm.Response, err error) { return g.wsmanMessages.CIM.KVMRedirectionSAP.RequestStateChange(requestedState) } diff --git a/internal/local/features.go b/internal/local/features.go index 8eb5519b..7816a030 100644 --- a/internal/local/features.go +++ b/internal/local/features.go @@ -39,7 +39,7 @@ func (service *ProvisioningService) SetAMTFeatures() error { return utils.AMTFeaturesConfigurationFailed } if !isISMSystem { - var kvmStateEnabled kvm.KVMRedirectionSAPRequestedStateInputs + var kvmStateEnabled kvm.KVMRedirectionSAPRequestStateChangeInput kvmStateEnabled = 3 // 3 (Disabled) - to disable the network interface of the feature if service.flags.KVM { kvmStateEnabled = 2 // 2 (Enabled) - to enable the network interface of the feature @@ -70,23 +70,23 @@ func (service *ProvisioningService) SetAMTFeatures() error { optInRequired = uint32(getOptInServiceResponse.Body.GetAndPutResponse.OptInRequired) switch service.flags.UserConsent { case "none": - optInRequired = uint32(optin.None) + optInRequired = uint32(optin.OptInRequiredNone) case "kvm": - optInRequired = uint32(optin.KVM) + optInRequired = uint32(optin.OptInRequiredKVM) case "all": - optInRequired = uint32(optin.All) + optInRequired = uint32(optin.OptInRequiredAll) } if uint32(getOptInServiceResponse.Body.GetAndPutResponse.OptInRequired) != optInRequired { //Put OptInService request := optin.OptInServiceRequest{ - CanModifyOptInPolicy: getOptInServiceResponse.Body.GetAndPutResponse.CanModifyOptInPolicy, + CanModifyOptInPolicy: int(getOptInServiceResponse.Body.GetAndPutResponse.CanModifyOptInPolicy), CreationClassName: getOptInServiceResponse.Body.GetAndPutResponse.CreationClassName, ElementName: getOptInServiceResponse.Body.GetAndPutResponse.ElementName, Name: getOptInServiceResponse.Body.GetAndPutResponse.Name, OptInCodeTimeout: getOptInServiceResponse.Body.GetAndPutResponse.OptInCodeTimeout, OptInDisplayTimeout: getOptInServiceResponse.Body.GetAndPutResponse.OptInDisplayTimeout, OptInRequired: int(optInRequired), - OptInState: getOptInServiceResponse.Body.GetAndPutResponse.OptInState, + OptInState: int(getOptInServiceResponse.Body.GetAndPutResponse.OptInState), SystemCreationClassName: getOptInServiceResponse.Body.GetAndPutResponse.SystemCreationClassName, SystemName: getOptInServiceResponse.Body.GetAndPutResponse.SystemName, } diff --git a/internal/local/lps_test.go b/internal/local/lps_test.go index f293f8d5..9e0b4477 100644 --- a/internal/local/lps_test.go +++ b/internal/local/lps_test.go @@ -6,6 +6,7 @@ package local import ( + "encoding/xml" "errors" "net/http" amt2 "rpc/internal/amt" @@ -118,7 +119,7 @@ func (m MockWSMAN) PutRedirectionState(requestedState redirection.RedirectionReq var mockRequestKVMStateChangeError error = nil var mockRequestKVMStateChangeResponse kvm.Response -func (m MockWSMAN) RequestKVMStateChange(requestedState kvm.KVMRedirectionSAPRequestedStateInputs) (response kvm.Response, err error) { +func (m MockWSMAN) RequestKVMStateChange(requestedState kvm.KVMRedirectionSAPRequestStateChangeInput) (response kvm.Response, err error) { return mockRequestKVMStateChangeResponse, mockRequestKVMStateChangeError } @@ -143,7 +144,7 @@ func (m MockWSMAN) CommitChanges() (response setupandconfiguration.Response, err return setupandconfiguration.Response{ Body: setupandconfiguration.Body{ CommitChanges_OUTPUT: setupandconfiguration.CommitChanges_OUTPUT{ - ReturnValue: mockCommitChangesReturnValue, + ReturnValue: setupandconfiguration.ReturnValue(mockCommitChangesReturnValue), }, }, }, mockCommitChangesErr @@ -177,7 +178,7 @@ func (m MockWSMAN) GenerateKeyPair(keyAlgorithm publickey.KeyAlgorithm, keyLengt return publickey.Response{ Body: publickey.Body{ GenerateKeyPair_OUTPUT: publickey.GenerateKeyPair_OUTPUT{ - ReturnValue: mockGenKeyPairReturnValue, + ReturnValue: publickey.ReturnValue(mockGenKeyPairReturnValue), KeyPair: publickey.KeyPairResponse{ ReferenceParameters: publickey.ReferenceParametersResponse{ SelectorSet: publickey.SelectorSetResponse{ @@ -250,7 +251,7 @@ func (m MockWSMAN) Unprovision(int) (setupandconfiguration.Response, error) { return setupandconfiguration.Response{ Body: setupandconfiguration.Body{ Unprovision_OUTPUT: setupandconfiguration.Unprovision_OUTPUT{ - ReturnValue: mockACMUnprovisionValue, + ReturnValue: setupandconfiguration.ReturnValue(mockACMUnprovisionValue), }, }, }, mockACMUnprovisionErr @@ -338,53 +339,79 @@ func (m MockWSMAN) DeletePublicCert(instanceId string) error { var errGetCredentialRelationships error = nil func (m MockWSMAN) GetCredentialRelationships() ([]credential.CredentialContext, error) { - return []credential.CredentialContext{{ - ElementInContext: models.AssociationReference{ - Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", - ReferenceParameters: models.ReferenceParmetersNoNamespace{ - ResourceURI: "http://intel.com/wbem/wscim/1/amt-schema/1/AMT_PublicKeyCertificate", - SelectorSet: []models.SelectorNoNamespace{ - { - Name: "InstanceID", - Value: "Intel(r) AMT Certificate: Handle: 2", + return []credential.CredentialContext{ + { + ElementInContext: models.AssociationReference{ + Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", + ReferenceParameters: models.ReferenceParametersNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.xmlsoap.org/ws/2004/08/addressing", Local: "ReferenceParameters"}, + ResourceURI: "http://intel.com/wbem/wscim/1/amt-schema/1/AMT_PublicKeyCertificate", + SelectorSet: models.SelectorNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "SelectorSet"}, + Selectors: []models.SelectorResponse{ + { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "InstanceID", + Text: "Intel(r) AMT Certificate: Handle: 2", + }, + }, }, }, }, - }, - ElementProvidingContext: models.AssociationReference{ - Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", - ReferenceParameters: models.ReferenceParmetersNoNamespace{ - ResourceURI: "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_IEEE8021xSettings", - SelectorSet: []models.SelectorNoNamespace{{ - Name: "InstanceID", - Value: "Intel(r) AMT:IEEE 802.1x Settings wifi8021x", - }}, + ElementProvidingContext: models.AssociationReference{ + Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", + ReferenceParameters: models.ReferenceParametersNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.xmlsoap.org/ws/2004/08/addressing", Local: "ReferenceParameters"}, + ResourceURI: "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_IEEE8021xSettings", + SelectorSet: models.SelectorNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "SelectorSet"}, + Selectors: []models.SelectorResponse{ + { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "InstanceID", + Text: "Intel(r) AMT:IEEE 802.1x Settings wifi8021x", + }, + }, + }, + }, }, - }, - }, { - ElementInContext: models.AssociationReference{ - Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", - ReferenceParameters: models.ReferenceParmetersNoNamespace{ - ResourceURI: "http://intel.com/wbem/wscim/1/amt-schema/1/AMT_PublicKeyCertificate", - SelectorSet: []models.SelectorNoNamespace{ - { - Name: "InstanceID", - Value: "Intel(r) AMT Certificate: Handle: 1", + }, { + ElementInContext: models.AssociationReference{ + Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", + ReferenceParameters: models.ReferenceParametersNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.xmlsoap.org/ws/2004/08/addressing", Local: "ReferenceParameters"}, + ResourceURI: "http://intel.com/wbem/wscim/1/amt-schema/1/AMT_PublicKeyCertificate", + SelectorSet: models.SelectorNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "SelectorSet"}, + Selectors: []models.SelectorResponse{ + { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "InstanceID", + Text: "Intel(r) AMT Certificate: Handle: 1", + }, + }, }, }, }, - }, - ElementProvidingContext: models.AssociationReference{ - Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", - ReferenceParameters: models.ReferenceParmetersNoNamespace{ - ResourceURI: "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_IEEE8021xSettings", - SelectorSet: []models.SelectorNoNamespace{{ - Name: "InstanceID", - Value: "Intel(r) AMT:IEEE 802.1x Settings wifi8021x", - }}, + ElementProvidingContext: models.AssociationReference{ + Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", + ReferenceParameters: models.ReferenceParametersNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.xmlsoap.org/ws/2004/08/addressing", Local: "ReferenceParameters"}, + ResourceURI: "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_IEEE8021xSettings", + SelectorSet: models.SelectorNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "SelectorSet"}, + Selectors: []models.SelectorResponse{ + { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "InstanceID", + Text: "Intel(r) AMT:IEEE 802.1x Settings wifi8021x", + }, + }, + }, + }, }, }, - }}, errGetCredentialRelationships + }, errGetCredentialRelationships } var errGetConcreteDependencies error = nil @@ -394,77 +421,122 @@ func (m MockWSMAN) GetConcreteDependencies() ([]concrete.ConcreteDependency, err { Antecedent: models.AssociationReference{ Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", - ReferenceParameters: models.ReferenceParmetersNoNamespace{ + ReferenceParameters: models.ReferenceParametersNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.xmlsoap.org/ws/2004/08/addressing", Local: "ReferenceParameters"}, ResourceURI: "http://intel.com/wbem/wscim/1/amt-schema/1/AMT_AssetTableService", - SelectorSet: []models.SelectorNoNamespace{{ - Name: "CreationClassName", - Value: "AMT_AssetTableService", - }, { - Name: "Name", - Value: "Intel(r) AMT Asset Table Service", - }, { - Name: "SystemCreationClassName", - Value: "CIM_ComputerSystem", - }, { - Name: "SystemName", - Value: "Intel(r) AMT", - }}, + SelectorSet: models.SelectorNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "SelectorSet"}, + Selectors: []models.SelectorResponse{ + { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "CreationClassName", + Text: "AMT_AssetTableService", + }, { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "Name", + Text: "Intel(r) AMT Asset Table Service", + }, { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "SystemCreationClassName", + Text: "CIM_ComputerSystem", + }, { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "SystemName", + Text: "Intel(r) AMT", + }, + }, + }, }, }, Dependent: models.AssociationReference{ Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", - ReferenceParameters: models.ReferenceParmetersNoNamespace{ + ReferenceParameters: models.ReferenceParametersNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.xmlsoap.org/ws/2004/08/addressing", Local: "ReferenceParameters"}, ResourceURI: "http://intel.com/wbem/wscim/1/amt-schema/1/AMT_AssetTable", - SelectorSet: []models.SelectorNoNamespace{{ - Name: "InstanceID", - Value: "1", - }, { - Name: "TableType", - Value: "131", - }}, + SelectorSet: models.SelectorNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "SelectorSet"}, + Selectors: []models.SelectorResponse{ + { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "InstanceID", + Text: "1", + }, { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "TableType", + Text: "131", + }, + }, + }, }, }, - }, - { + }, { Antecedent: models.AssociationReference{ Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", - ReferenceParameters: models.ReferenceParmetersNoNamespace{ + ReferenceParameters: models.ReferenceParametersNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.xmlsoap.org/ws/2004/08/addressing", Local: "ReferenceParameters"}, ResourceURI: "http://intel.com/wbem/wscim/1/amt-schema/1/AMT_PublicKeyCertificate", - SelectorSet: []models.SelectorNoNamespace{{ - Name: "InstanceID", - Value: "Intel(r) AMT Certificate: Handle: 1", - }}, + SelectorSet: models.SelectorNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "SelectorSet"}, + Selectors: []models.SelectorResponse{ + { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "InstanceID", + Text: "Intel(r) AMT Certificate: Handle: 1", + }, + }, + }, }, }, Dependent: models.AssociationReference{ Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", - ReferenceParameters: models.ReferenceParmetersNoNamespace{ + ReferenceParameters: models.ReferenceParametersNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.xmlsoap.org/ws/2004/08/addressing", Local: "ReferenceParameters"}, ResourceURI: "http://intel.com/wbem/wscim/1/amt-schema/1/AMT_PublicPrivateKeyPair", - SelectorSet: []models.SelectorNoNamespace{{ - Name: "InstanceID", - Value: "Intel(r) AMT Key: Handle: 0", - }}, + SelectorSet: models.SelectorNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "SelectorSet"}, + Selectors: []models.SelectorResponse{ + { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "InstanceID", + Text: "Intel(r) AMT Key: Handle: 0", + }, + }, + }, }, }, }, { Antecedent: models.AssociationReference{ Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", - ReferenceParameters: models.ReferenceParmetersNoNamespace{ + ReferenceParameters: models.ReferenceParametersNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.xmlsoap.org/ws/2004/08/addressing", Local: "ReferenceParameters"}, ResourceURI: "http://intel.com/wbem/wscim/1/amt-schema/1/AMT_PublicKeyCertificate", - SelectorSet: []models.SelectorNoNamespace{{ - Name: "InstanceID", - Value: "Intel(r) AMT Certificate: Handle: 1", - }}, + SelectorSet: models.SelectorNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "SelectorSet"}, + Selectors: []models.SelectorResponse{ + { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "InstanceID", + Text: "Intel(r) AMT Certificate: Handle: 1", + }, + }, + }, }, }, Dependent: models.AssociationReference{ Address: "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous", - ReferenceParameters: models.ReferenceParmetersNoNamespace{ + ReferenceParameters: models.ReferenceParametersNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.xmlsoap.org/ws/2004/08/addressing", Local: "ReferenceParameters"}, ResourceURI: "http://intel.com/wbem/wscim/1/amt-schema/1/AMT_SOME_UNHANDLED_RESOURCE_FOR_TESTING", - SelectorSet: []models.SelectorNoNamespace{{ - Name: "InstanceID", - Value: "Intel(r) AMT Key: Handle: 0", - }}, + SelectorSet: models.SelectorNoNamespace{ + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "SelectorSet"}, + Selectors: []models.SelectorResponse{ + { + XMLName: xml.Name{Space: "http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", Local: "Selector"}, + Name: "InstanceID", + Text: "Intel(r) AMT Key: Handle: 0", + }, + }, + }, }, }, }, diff --git a/internal/local/wifi.go b/internal/local/wifi.go index b22af0dd..b79970a2 100644 --- a/internal/local/wifi.go +++ b/internal/local/wifi.go @@ -14,6 +14,7 @@ import ( "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/models" "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/cim/wifi" + "github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman/ips/ieee8021x" log "github.com/sirupsen/logrus" ) @@ -241,7 +242,7 @@ func (service *ProvisioningService) setIeee8021xConfig(ieee8021xConfig *config.I AuthenticationProtocol: models.AuthenticationProtocol(ieee8021xConfig.AuthenticationProtocol), Username: ieee8021xConfig.Username, } - if ieee8021xSettings.AuthenticationProtocol == models.AuthenticationProtocolPEAPv0_EAPMSCHAPv2 { + if ieee8021xSettings.AuthenticationProtocol == models.AuthenticationProtocol(ieee8021x.AuthenticationProtocolPEAPv0_EAPMSCHAPv2) { ieee8021xSettings.Password = ieee8021xConfig.Password } if ieee8021xConfig.PrivateKey != "" { diff --git a/internal/local/wifi_test.go b/internal/local/wifi_test.go index 06e9800f..60a5e822 100644 --- a/internal/local/wifi_test.go +++ b/internal/local/wifi_test.go @@ -27,7 +27,7 @@ var wifiCfgWPA = config.WifiConfig{ ProfileName: "wifiWPA", SSID: "ssid", Priority: 1, - AuthenticationMethod: int(wifi.AuthenticationMethod_WPA_PSK), + AuthenticationMethod: int(wifi.AuthenticationMethodWPAPSK), EncryptionMethod: int(wifi.EncryptionMethod_CCMP), PskPassphrase: "wifiWPAPassPhrase", Ieee8021xProfileName: "", @@ -37,7 +37,7 @@ var wifiCfgWPA2 = config.WifiConfig{ ProfileName: "wifiWPA2", SSID: "ssid", Priority: 2, - AuthenticationMethod: int(wifi.AuthenticationMethod_WPA2_PSK), + AuthenticationMethod: int(wifi.AuthenticationMethodWPA2PSK), EncryptionMethod: int(wifi.EncryptionMethod_CCMP), PskPassphrase: "wifiWPAPassPhrase", Ieee8021xProfileName: "", @@ -47,7 +47,7 @@ var wifiCfgWPA8021xEAPTLS = config.WifiConfig{ ProfileName: "wifiWPA28021x", SSID: "ssid", Priority: 2, - AuthenticationMethod: int(wifi.AuthenticationMethod_WPA_IEEE8021x), + AuthenticationMethod: int(wifi.AuthenticationMethodWPAIEEE8021x), EncryptionMethod: int(wifi.EncryptionMethod_CCMP), PskPassphrase: "", Ieee8021xProfileName: "ieee8021xCfgEAPTLS", @@ -107,7 +107,7 @@ func TestProcessWifiConfig(t *testing.T) { // bad name error already tested t.Run("expect success when handling ieee8021x config", func(t *testing.T) { orig := wifiCfgWPA8021xEAPTLS.AuthenticationMethod - wifiCfgWPA8021xEAPTLS.AuthenticationMethod = int(wifi.AuthenticationMethod_WPA_IEEE8021x) + wifiCfgWPA8021xEAPTLS.AuthenticationMethod = int(wifi.AuthenticationMethodWPAIEEE8021x) f.LocalConfig.Ieee8021xConfigs = []config.Ieee8021xConfig{ ieee8021xCfgEAPTLS, }