| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- #!/usr/bin/env python3
- #
- # Copyright (c) 2022 Project CHIP Authors
- # All rights reserved.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- #
- '''This file should contain custom classes derived any class from default.py.
- Each class implemented here should describe an input parameter and should
- implement the InputArgument abstract interface, if its base class does not
- already offer an implementation or if there is a need of a custom behavior.
- Example of defining a new argument class:
- class FooArgument(IntArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return <unique key identifier>
- def length(self):
- return <actual length of data>
- def encode(self):
- return <data as encoded bytes>
- def custom_function(self):
- pass
- Then use this class in generate.py to create a FooArgument object from an
- option:
- parser.add_argument("--foo", required=True, type=FooArgument,
- help="[int | hex] Foo argument.")
- '''
- from cryptography.hazmat.backends import default_backend
- from cryptography.hazmat.primitives.serialization import load_der_private_key
- from default import Base64Argument, FileArgument, IntArgument, StrArgument
- class Verifier(Base64Argument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 1
- class Salt(Base64Argument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 2
- class IterationCount(IntArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 3
- class DacPKey(FileArgument):
- def __init__(self, arg):
- super().__init__(arg)
- self.private_key = None
- def key(self):
- return 4
- def length(self):
- assert (self.private_key is not None)
- return len(self.private_key)
- def encode(self):
- assert (self.private_key is not None)
- return self.private_key
- def generate_private_key(self, password):
- keys = load_der_private_key(self.val, password, backend=default_backend())
- self.private_key = keys.private_numbers().private_value.to_bytes(
- 32, byteorder='big'
- )
- class DacCert(FileArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 5
- class PaiCert(FileArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 6
- class Discriminator(IntArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 7
- class SetupPasscode(IntArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 8
- class VendorId(IntArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 9
- def length(self):
- return 2
- class ProductId(IntArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 10
- def length(self):
- return 2
- class CertDeclaration(FileArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 11
- class VendorName(StrArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 12
- class ProductName(StrArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 13
- class SerialNum(StrArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 14
- class ManufacturingDate(StrArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 15
- def max_length(self):
- return 16
- class HardwareVersion(IntArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 16
- def length(self):
- return 2
- class HardwareVersionStr(StrArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 17
- def max_length(self):
- return 64
- class UniqueId(StrArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 18
- class PartNumber(StrArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 19
- class ProductURL(StrArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 20
- def max_length(self):
- return 256
- class ProductLabel(StrArgument):
- def __init__(self, arg):
- super().__init__(arg)
- def key(self):
- return 21
- def max_length(self):
- return 64
|