Skip to content

Commit 1726eb3

Browse files
Update macsec CAK keys in profile for tests to change to type7 encoded format (#16388) (#16626)
* Change the CAK key length check in config plugin, macsec test profile changes * Fix the format in add_profile api The changes needed in various macsec unit tests and config plugin when we move to accept the type 7 encoded key format for macsec. This goes along with PR : sonic-net/sonic-swss#2892 raised earlier. Co-authored-by: judyjoseph <[email protected]>
1 parent a713299 commit 1726eb3

File tree

7 files changed

+29
-33
lines changed

7 files changed

+29
-33
lines changed

dockers/docker-macsec/cli-plugin-tests/config_db.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"MACSEC_PROFILE|macsec_profile": {
33
"cipher_suite": "GCM-AES-XPN-256",
44
"policy": "security",
5-
"primary_cak": "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF",
5+
"primary_cak": "5207554155500e5d5157786d6c2a3d2031425a5e577e7e727f6b6c03312432262706080a00005b554f4e007975707670725b0a54540c0252445e5d7a29252b046a",
66
"primary_ckn": "6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435",
77
"priority": "0",
88
"rekey_period": "900",

dockers/docker-macsec/cli-plugin-tests/test_config_macsec.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
profile_name = "test"
11-
primary_cak = "01234567890123456789012345678912"
11+
primary_cak = "2363647040534355560e000802065d574d400e000e030307075f0e5050000e5541"
1212
primary_ckn = "01234567890123456789012345678912"
1313

1414

@@ -48,7 +48,7 @@ def test_macsec_valid_profile(self, mock_cfgdb):
4848

4949
profile_name = "test"
5050
profile_map = {
51-
"primary_cak": "0123456789012345678901234567891201234567890123456789012345678912",
51+
"primary_cak": "3946080a0407070303530256560a04504650530352565e731f1a5c4f524f4b5a5e547b79777c6663754b5e465253050d0d0503565a48470b0b030604020c520a54",
5252
"primary_ckn": "01234567890123456789012345678912",
5353
"priority": 64,
5454
"cipher_suite": "GCM-AES-XPN-256",
@@ -109,7 +109,7 @@ def test_macsec_port(self, mock_cfgdb):
109109
runner = CliRunner()
110110

111111
result = runner.invoke(macsec.macsec, ["profile", "add", "test",
112-
"--primary_cak=01234567890123456789012345678912","--primary_ckn=01234567890123456789012345678912"],
112+
"--primary_cak=2363647040534355560e000802065d574d400e000e030307075f0e5050000e5541","--primary_ckn=01234567890123456789012345678912"],
113113
obj=cfgdb)
114114
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
115115
result = runner.invoke(macsec.macsec, ["port", "add", "Ethernet0", "test"], obj=cfgdb)
@@ -141,8 +141,8 @@ def test_macsec_invalid_operation(self, mock_cfgdb):
141141
result = runner.invoke(macsec.macsec, ["profile", "del", "test"], obj=cfgdb)
142142
assert result.exit_code != 0
143143

144-
result = runner.invoke(macsec.macsec, ["profile", "add", "test", "--primary_cak=01234567890123456789012345678912","--primary_ckn=01234567890123456789012345678912"], obj=cfgdb)
144+
result = runner.invoke(macsec.macsec, ["profile", "add", "test", "--primary_cak=2363647040534355560e000802065d574d400e000e030307075f0e5050000e5541","--primary_ckn=01234567890123456789012345678912"], obj=cfgdb)
145145
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
146146
# Repeat add profile
147-
result = runner.invoke(macsec.macsec, ["profile", "add", "test", "--primary_cak=01234567890123456789012345678912","--primary_ckn=01234567890123456789012345678912"], obj=cfgdb)
147+
result = runner.invoke(macsec.macsec, ["profile", "add", "test", "--primary_cak=2363647040534355560e000802065d574d400e000e030307075f0e5050000e5541","--primary_ckn=01234567890123456789012345678912"], obj=cfgdb)
148148
assert result.exit_code != 0

dockers/docker-macsec/cli/config/plugins/macsec.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ def add_profile(profile, priority, cipher_suite, primary_cak, primary_ckn, polic
137137
profile_table["cipher_suite"] = cipher_suite
138138

139139
if "128" in cipher_suite:
140-
if len(primary_cak) != 32:
141-
ctx.fail("Expect the length of CAK is 32, but got {}".format(len(primary_cak)))
140+
if len(primary_cak) != 66:
141+
ctx.fail("Expect the length of CAK is 66, but got {}".format(len(primary_cak)))
142142
elif "256" in cipher_suite:
143-
if len(primary_cak) != 64:
144-
ctx.fail("Expect the length of CAK is 64, but got {}".format(len(primary_cak)))
143+
if len(primary_cak) != 130:
144+
ctx.fail("Expect the length of CAK is 130, but got {}".format(len(primary_cak)))
145145
if not is_hexstring(primary_cak):
146146
ctx.fail("Expect the primary_cak is valid hex string")
147147
if not is_hexstring(primary_ckn):

src/sonic-config-engine/tests/macsec_profile.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
"MACSEC_PROFILE":{
33
"macsec-profile": {
44
"cipher_suite": "GCM-AES-XPN-256",
5-
"primary_cak": "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF",
5+
"primary_cak": "5207554155500e5d5157786d6c2a3d2031425a5e577e7e727f6b6c03312432262706080a00005b554f4e007975707670725b0a54540c0252445e5d7a29252b046a",
66
"primary_ckn": "6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435",
7-
"fallback_cak": "0000000000000000000000000000000000000000000000000000000000000000",
7+
"fallback_cak": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
88
"fallback_ckn": "1111111111111111111111111111111111111111111111111111111111111111",
99
"priority": "0",
1010
"rekey_period": "60"
1111
},
1212
"macsec-profile2": {
1313
"cipher_suite": "GCM-AES-XPN-256",
14-
"primary_cak": "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF",
14+
"primary_cak": "5207554155500e5d5157786d6c2a3d2031425a5e577e7e727f6b6c03312432262706080a00005b554f4e007975707670725b0a54540c0252445e5d7a29252b046a",
1515
"primary_ckn": "6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435",
16-
"fallback_cak": "0000000000000000000000000000000000000000000000000000000000000000",
16+
"fallback_cak": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
1717
"fallback_ckn": "1111111111111111111111111111111111111111111111111111111111111111",
1818
"priority": "0",
1919
"rekey_period": "60"

src/sonic-yang-models/tests/files/sample_config_db.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2258,9 +2258,9 @@
22582258
"test": {
22592259
"priority": "64",
22602260
"cipher_suite": "GCM-AES-128",
2261-
"primary_cak": "0123456789ABCDEF0123456789ABCDEF",
2261+
"primary_cak": "1159485744465e5a537272050a1011073557475152020c0e040c57223a357d7d71",
22622262
"primary_ckn": "6162636465666768696A6B6C6D6E6F70",
2263-
"fallback_cak": "00000000000000000000000000000000",
2263+
"fallback_cak": "000000000000000000000000000000000000000000000000000000000000000000",
22642264
"fallback_ckn": "11111111111111111111111111111111",
22652265
"policy": "security",
22662266
"enable_replay_protect": "true",

src/sonic-yang-models/tests/yang_model_tests/tests_config/macsec.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"name": "test32",
88
"priority": 64,
99
"cipher_suite": "GCM-AES-128",
10-
"primary_cak": "0123456789ABCDEF0123456789ABCDEF",
10+
"primary_cak": "1159485744465e5a537272050a1011073557475152020c0e040c57223a357d7d71",
1111
"primary_ckn": "6162636465666768696A6B6C6D6E6F70",
12-
"fallback_cak": "00000000000000000000000000000000",
12+
"fallback_cak": "000000000000000000000000000000000000000000000000000000000000000000",
1313
"fallback_ckn": "11111111111111111111111111111111",
1414
"policy": "security",
1515
"enable_replay_protect": "true",
@@ -21,9 +21,9 @@
2121
"name": "test64",
2222
"priority": 64,
2323
"cipher_suite": "GCM-AES-XPN-256",
24-
"primary_cak": "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF",
24+
"primary_cak": "5207554155500e5d5157786d6c2a3d2031425a5e577e7e727f6b6c03312432262706080a00005b554f4e007975707670725b0a54540c0252445e5d7a29252b046a",
2525
"primary_ckn": "6162636465666768696A6B6C6D6E6F706162636465666768696A6B6C6D6E6F70",
26-
"fallback_cak": "0000000000000000000000000000000000000000000000000000000000000000",
26+
"fallback_cak": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
2727
"fallback_ckn": "1111111111111111111111111111111111111111111111111111111111111111",
2828
"policy": "security",
2929
"enable_replay_protect": "true",
@@ -61,7 +61,7 @@
6161
{
6262
"name": "test",
6363
"cipher_suite": "gcm-aes-128",
64-
"primary_cak": "0123456789ABCDEF0123456789ABCDEF",
64+
"primary_cak": "1159485744465e5a537272050a1011073557475152020c0e040c57223a357d7d71",
6565
"primary_ckn": "6162636465666768696A6B6C6D6E6F70"
6666
}
6767
]
@@ -74,9 +74,9 @@
7474
"MACSEC_PROFILE_LIST": [
7575
{
7676
"name": "test",
77-
"primary_cak": "0123456789ABCDEF0123456789ABCDEF",
77+
"primary_cak": "1159485744465e5a537272050a1011073557475152020c0e040c57223a357d7d71",
7878
"primary_ckn": "6162636465666768696A6B6C6D6E6F70",
79-
"fallback_cak": "0123456789ABCDEF0123456789ABCDEF",
79+
"fallback_cak": "1159485744465e5a537272050a1011073557475152020c0e040c57223a357d7d71",
8080
"fallback_ckn": "6162636465666768696A6B6C6D6E6F70"
8181
}
8282
]
@@ -89,7 +89,7 @@
8989
"MACSEC_PROFILE_LIST": [
9090
{
9191
"name": "test",
92-
"primary_cak": "0123456789ABCDEF0123456789ABCDEFA",
92+
"primary_cak": "1159485744465e5a537272050a1011073557475152020c0e040c57223a357d7d7",
9393
"primary_ckn": "6162636465666768696A6B6C6D6E6F70A"
9494
}
9595
]
@@ -115,9 +115,9 @@
115115
"MACSEC_PROFILE_LIST": [
116116
{
117117
"name": "test",
118-
"primary_cak": "0123456789ABCDEF0123456789ABCDEF",
118+
"primary_cak": "1159485744465e5a537272050a1011073557475152020c0e040c57223a357d7d71",
119119
"primary_ckn": "6162636465666768696A6B6C6D6E6F70",
120-
"fallback_cak": "0000000000000000000000000000000000000000000000000000000000000000",
120+
"fallback_cak": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
121121
"fallback_ckn": "1111111111111111111111111111111111111111111111111111111111111111"
122122
}
123123
]
@@ -130,7 +130,7 @@
130130
"MACSEC_PROFILE_LIST": [
131131
{
132132
"name": "test",
133-
"primary_cak": "0123456789ABCDEF0123456789ABCDEF",
133+
"primary_cak": "1159485744465e5a537272050a1011073557475152020c0e040c57223a357d7d71",
134134
"primary_ckn": "6162636465666768696A6B6C6D6E6F70",
135135
"replay_window": 64
136136
}

src/sonic-yang-models/yang-models/sonic-macsec.yang

+2-6
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module sonic-macsec {
4646

4747
leaf primary_cak {
4848
type string {
49-
pattern "[0-9a-fA-F]{32}|[0-9a-fA-F]{64}";
49+
pattern "[0-9a-fA-F]{66}|[0-9a-fA-F]{130}";
5050
}
5151
mandatory true;
5252
}
@@ -60,7 +60,7 @@ module sonic-macsec {
6060

6161
leaf fallback_cak {
6262
type string {
63-
pattern "[0-9a-fA-F]{32}|[0-9a-fA-F]{64}";
63+
pattern "[0-9a-fA-F]{66}|[0-9a-fA-F]{130}";
6464
}
6565
}
6666

@@ -70,10 +70,6 @@ module sonic-macsec {
7070
}
7171
}
7272

73-
must "string-length(primary_cak) = string-length(primary_ckn)";
74-
75-
must "string-length(fallback_cak) = string-length(fallback_ckn)";
76-
7773
must "string-length(fallback_cak) = string-length(primary_cak)";
7874

7975
must "primary_ckn != fallback_ckn";

0 commit comments

Comments
 (0)