@@ -0,0 +1,2184 @@
+##############################################################################%0A# The MIT License (MIT)%0A#%0A# Copyright (c) 2016-2019 Hajime Nakagami%3Cnakagami@gmail.com%3E%0A#%0A# Permission is hereby granted, free of charge, to any person obtaining a copy%0A# of this software and associated documentation files (the %22Software%22), to deal%0A# in the Software without restriction, including without limitation the rights%0A# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A# copies of the Software, and to permit persons to whom the Software is%0A# furnished to do so, subject to the following conditions:%0A#%0A# The above copyright notice and this permission notice shall be included in all%0A# copies or substantial portions of the Software.%0A#%0A# THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE%0A# SOFTWARE.%0A##############################################################################%0A# https://wiki.apache.org/db-derby/SecurityMechanism%0A%0Aimport random%0Aimport pyDes%0A%0A%0A# DH Key exchange%0A# https://en.wikipedia.org/wiki/Diffie-Hellman_key_exchange%0A%0A# p%0Aprime = 0xC62112D73EE613F0947AB31F0F6846A1BFF5B3A4CA0D60BC1E4C7A0D8C16B3E3%0A# g%0Abase = 0x4690FA1F7B9E1D4442C86C9114603FDECF071EDCEC5F626E21E256AED9EA34E4%0A%0A%0Adef get_private():%0A    return random.randrange(2, prime)%0A%0A%0Adef calc_public(private):%0A    return pow(base, private, prime)%0A%0A%0Adef calc_session_key(public, private):%0A    return pow(public, private, prime).to_bytes(32, byteorder='big')%0A%0A%0A# DES/CBC/PKCS5Padding encryption%0Adef des(sever_sectkn, client_private):%0A    assert len(server_sectkn) == 32%0A    # TODO: calculate session key from server_sectkn and client_private%0A    #       get des key (8bytes) from session key%0A%0A    iv = server_sectkn%5B12:20%5D%0A    return pyDes.des(key, pyDes.CBC, iv, None, pyDes.PAD_PKCS5)%0A

add secmec9.py