Skip to content

Commit

Permalink
fix: use go-wsman-messages v2.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbrache committed Apr 19, 2024
1 parent 396efc4 commit e2e568f
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 143 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion internal/flags/activate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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` +
Expand Down
33 changes: 12 additions & 21 deletions internal/flags/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
34 changes: 15 additions & 19 deletions internal/flags/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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",
}
Expand All @@ -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",
}
Expand All @@ -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",
}
Expand All @@ -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",
Expand All @@ -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",
}
Expand Down Expand Up @@ -538,15 +537,15 @@ 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{})
wifiCfgWPA.AuthenticationMethod = orig
})
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{})
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/local/amt/wsman.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
12 changes: 6 additions & 6 deletions internal/local/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down
Loading

0 comments on commit e2e568f

Please sign in to comment.