Hex Artifact Content

Artifact 2fbb069da4591cbb401a0e85b01ac322caae9fca:


0000: 23 21 20 2f 75 73 72 2f 62 69 6e 2f 65 6e 76 20  #! /usr/bin/env 
0010: 73 68 0a 0a 62 69 74 73 3d 27 32 30 34 38 27 0a  sh..bits='2048'.
0020: 0a 6f 70 65 6e 73 73 6c 5f 64 68 70 61 72 61 6d  .openssl_dhparam
0030: 28 29 20 7b 0a 09 69 66 20 5b 20 2d 78 20 22 60  () {..if [ -x "`
0040: 77 68 69 63 68 20 6f 70 65 6e 73 73 6c 20 32 3e  which openssl 2>
0050: 2f 64 65 76 2f 6e 75 6c 6c 60 22 20 5d 3b 20 74  /dev/null`" ]; t
0060: 68 65 6e 0a 09 09 6f 5f 6f 75 74 70 75 74 3d 22  hen...o_output="
0070: 60 6f 70 65 6e 73 73 6c 20 64 68 70 61 72 61 6d  `openssl dhparam
0080: 20 2d 43 20 22 24 40 22 20 32 3e 2f 64 65 76 2f   -C "$@" 2>/dev/
0090: 6e 75 6c 6c 60 22 20 7c 7c 20 72 65 74 75 72 6e  null`" || return
00a0: 20 31 0a 09 09 6f 5f 6f 75 74 70 75 74 3d 22 60   1...o_output="`
00b0: 65 63 68 6f 20 22 24 7b 6f 5f 6f 75 74 70 75 74  echo "${o_output
00c0: 7d 22 20 7c 20 73 65 64 20 27 2f 5e 2d 2d 2d 2d  }" | sed '/^----
00d0: 2d 42 45 47 49 4e 20 44 48 20 50 41 52 41 4d 45  -BEGIN DH PARAME
00e0: 54 45 52 53 2d 2d 2d 2d 2d 24 2f 2c 2f 5e 2d 2d  TERS-----$/,/^--
00f0: 2d 2d 2d 45 4e 44 20 44 48 20 50 41 52 41 4d 45  ---END DH PARAME
0100: 54 45 52 53 2d 2d 2d 2d 2d 24 2f 20 64 3b 2f 5e  TERS-----$/ d;/^
0110: 23 2f 20 64 27 60 22 20 7c 7c 20 72 65 74 75 72  #/ d'`" || retur
0120: 6e 20 31 0a 0a 09 09 65 63 68 6f 20 22 24 7b 6f  n 1....echo "${o
0130: 5f 6f 75 74 70 75 74 7d 22 0a 0a 09 09 72 65 74  _output}"....ret
0140: 75 72 6e 20 30 0a 09 66 69 0a 0a 09 72 65 74 75  urn 0..fi...retu
0150: 72 6e 20 31 0a 7d 0a 0a 67 65 6e 5f 64 68 5f 70  rn 1.}..gen_dh_p
0160: 61 72 61 6d 73 5f 6f 70 65 6e 73 73 6c 28 29 20  arams_openssl() 
0170: 7b 0a 09 6f 70 65 6e 73 73 6c 5f 64 68 70 61 72  {..openssl_dhpar
0180: 61 6d 20 22 24 7b 62 69 74 73 7d 22 20 3c 20 2f  am "${bits}" < /
0190: 64 65 76 2f 6e 75 6c 6c 20 7c 7c 20 72 65 74 75  dev/null || retu
01a0: 72 6e 20 31 0a 09 72 65 74 75 72 6e 20 30 0a 7d  rn 1..return 0.}
01b0: 0a 0a 67 65 6e 5f 64 68 5f 70 61 72 61 6d 73 5f  ..gen_dh_params_
01c0: 72 65 6d 6f 74 65 28 29 20 7b 0a 09 75 72 6c 3d  remote() {..url=
01d0: 22 68 74 74 70 73 3a 2f 2f 32 74 6f 6e 2e 63 6f  "https://2ton.co
01e0: 6d 2e 61 75 2f 64 68 70 61 72 61 6d 2f 24 7b 62  m.au/dhparam/${b
01f0: 69 74 73 7d 22 0a 0a 09 72 5f 69 6e 70 75 74 3d  its}"...r_input=
0200: 22 60 63 75 72 6c 20 2d 73 53 20 22 24 7b 75 72  "`curl -sS "${ur
0210: 6c 7d 22 60 22 20 7c 7c 20 5c 0a 09 09 72 5f 69  l}"`" || \...r_i
0220: 6e 70 75 74 3d 22 60 77 67 65 74 20 2d 4f 20 2d  nput="`wget -O -
0230: 20 2d 6f 20 2f 64 65 76 2f 6e 75 6c 6c 20 22 24   -o /dev/null "$
0240: 7b 75 72 6c 7d 22 60 22 20 7c 7c 20 72 65 74 75  {url}"`" || retu
0250: 72 6e 20 31 0a 0a 09 69 66 20 72 5f 6f 75 74 70  rn 1...if r_outp
0260: 75 74 3d 22 60 65 63 68 6f 20 22 24 7b 72 5f 69  ut="`echo "${r_i
0270: 6e 70 75 74 7d 22 20 7c 20 6f 70 65 6e 73 73 6c  nput}" | openssl
0280: 5f 64 68 70 61 72 61 6d 60 22 3b 20 74 68 65 6e  _dhparam`"; then
0290: 0a 09 09 65 63 68 6f 20 22 24 7b 72 5f 6f 75 74  ...echo "${r_out
02a0: 70 75 74 7d 22 0a 0a 09 09 72 65 74 75 72 6e 20  put}"....return 
02b0: 30 0a 09 66 69 0a 0a 09 72 65 74 75 72 6e 20 31  0..fi...return 1
02c0: 0a 7d 0a 0a 67 65 6e 5f 64 68 5f 70 61 72 61 6d  .}..gen_dh_param
02d0: 73 5f 66 61 6c 6c 62 61 63 6b 28 29 20 7b 0a 09  s_fallback() {..
02e0: 63 61 74 20 3c 3c 20 5c 5f 45 4f 46 5f 0a 44 48  cat << \_EOF_.DH
02f0: 20 2a 67 65 74 5f 64 68 32 30 34 38 28 76 6f 69   *get_dh2048(voi
0300: 64 29 20 7b 0a 09 73 74 61 74 69 63 20 75 6e 73  d) {..static uns
0310: 69 67 6e 65 64 20 63 68 61 72 20 64 68 70 5f 32  igned char dhp_2
0320: 30 34 38 5b 5d 20 3d 20 7b 0a 09 09 30 78 43 31  048[] = {...0xC1
0330: 2c 30 78 35 31 2c 30 78 35 38 2c 30 78 36 39 2c  ,0x51,0x58,0x69,
0340: 30 78 46 42 2c 30 78 45 38 2c 30 78 36 43 2c 30  0xFB,0xE8,0x6C,0
0350: 78 34 37 2c 30 78 32 42 2c 30 78 38 36 2c 30 78  x47,0x2B,0x86,0x
0360: 36 31 2c 30 78 34 46 2c 0a 09 09 30 78 32 30 2c  61,0x4F,...0x20,
0370: 30 78 32 45 2c 30 78 44 33 2c 30 78 46 43 2c 30  0x2E,0xD3,0xFC,0
0380: 78 31 39 2c 30 78 45 45 2c 30 78 42 38 2c 30 78  x19,0xEE,0xB8,0x
0390: 46 33 2c 30 78 33 35 2c 30 78 37 44 2c 30 78 42  F3,0x35,0x7D,0xB
03a0: 41 2c 30 78 38 36 2c 0a 09 09 30 78 32 41 2c 30  A,0x86,...0x2A,0
03b0: 78 43 33 2c 30 78 43 38 2c 30 78 36 45 2c 30 78  xC3,0xC8,0x6E,0x
03c0: 46 34 2c 30 78 39 39 2c 30 78 37 35 2c 30 78 36  F4,0x99,0x75,0x6
03d0: 35 2c 30 78 44 33 2c 30 78 37 41 2c 30 78 39 45  5,0xD3,0x7A,0x9E
03e0: 2c 30 78 44 46 2c 0a 09 09 30 78 44 34 2c 30 78  ,0xDF,...0xD4,0x
03f0: 31 46 2c 30 78 38 38 2c 30 78 45 33 2c 30 78 31  1F,0x88,0xE3,0x1
0400: 37 2c 30 78 46 43 2c 30 78 41 31 2c 30 78 45 44  7,0xFC,0xA1,0xED
0410: 2c 30 78 41 32 2c 30 78 42 36 2c 30 78 37 37 2c  ,0xA2,0xB6,0x77,
0420: 30 78 38 34 2c 0a 09 09 30 78 41 41 2c 30 78 30  0x84,...0xAA,0x0
0430: 38 2c 30 78 46 32 2c 30 78 39 37 2c 30 78 35 39  8,0xF2,0x97,0x59
0440: 2c 30 78 37 41 2c 30 78 41 30 2c 30 78 30 33 2c  ,0x7A,0xA0,0x03,
0450: 30 78 30 44 2c 30 78 33 45 2c 30 78 37 45 2c 30  0x0D,0x3E,0x7E,0
0460: 78 36 44 2c 0a 09 09 30 78 36 35 2c 30 78 36 41  x6D,...0x65,0x6A
0470: 2c 30 78 41 34 2c 30 78 45 41 2c 30 78 35 34 2c  ,0xA4,0xEA,0x54,
0480: 30 78 41 39 2c 30 78 35 32 2c 30 78 35 46 2c 30  0xA9,0x52,0x5F,0
0490: 78 36 33 2c 30 78 42 34 2c 30 78 42 43 2c 30 78  x63,0xB4,0xBC,0x
04a0: 39 38 2c 0a 09 09 30 78 34 45 2c 30 78 46 36 2c  98,...0x4E,0xF6,
04b0: 30 78 45 31 2c 30 78 41 34 2c 30 78 45 45 2c 30  0xE1,0xA4,0xEE,0
04c0: 78 31 36 2c 30 78 30 41 2c 30 78 42 30 2c 30 78  x16,0x0A,0xB0,0x
04d0: 30 31 2c 30 78 42 44 2c 30 78 39 46 2c 30 78 41  01,0xBD,0x9F,0xA
04e0: 31 2c 0a 09 09 30 78 45 38 2c 30 78 32 33 2c 30  1,...0xE8,0x23,0
04f0: 78 32 39 2c 30 78 35 36 2c 30 78 34 30 2c 30 78  x29,0x56,0x40,0x
0500: 39 35 2c 30 78 31 33 2c 30 78 45 42 2c 30 78 43  95,0x13,0xEB,0xC
0510: 42 2c 30 78 44 35 2c 30 78 46 43 2c 30 78 37 36  B,0xD5,0xFC,0x76
0520: 2c 0a 09 09 30 78 31 41 2c 30 78 34 31 2c 30 78  ,...0x1A,0x41,0x
0530: 32 36 2c 30 78 43 45 2c 30 78 32 30 2c 30 78 45  26,0xCE,0x20,0xE
0540: 42 2c 30 78 33 30 2c 30 78 31 30 2c 30 78 31 37  B,0x30,0x10,0x17
0550: 2c 30 78 30 37 2c 30 78 45 31 2c 30 78 38 43 2c  ,0x07,0xE1,0x8C,
0560: 0a 09 09 30 78 41 43 2c 30 78 35 37 2c 30 78 33  ...0xAC,0x57,0x3
0570: 37 2c 30 78 38 42 2c 30 78 45 38 2c 30 78 30 31  7,0x8B,0xE8,0x01
0580: 2c 30 78 44 45 2c 30 78 41 39 2c 30 78 45 46 2c  ,0xDE,0xA9,0xEF,
0590: 30 78 41 34 2c 30 78 43 32 2c 30 78 41 34 2c 0a  0xA4,0xC2,0xA4,.
05a0: 09 09 30 78 36 45 2c 30 78 34 38 2c 30 78 32 35  ..0x6E,0x48,0x25
05b0: 2c 30 78 31 31 2c 30 78 33 33 2c 30 78 31 31 2c  ,0x11,0x33,0x11,
05c0: 30 78 44 34 2c 30 78 35 32 2c 30 78 37 39 2c 30  0xD4,0x52,0x79,0
05d0: 78 38 37 2c 30 78 39 46 2c 30 78 37 35 2c 0a 09  x87,0x9F,0x75,..
05e0: 09 30 78 36 31 2c 30 78 46 37 2c 30 78 39 43 2c  .0x61,0xF7,0x9C,
05f0: 30 78 37 44 2c 30 78 33 36 2c 30 78 34 31 2c 30  0x7D,0x36,0x41,0
0600: 78 43 42 2c 30 78 45 43 2c 30 78 38 46 2c 30 78  xCB,0xEC,0x8F,0x
0610: 45 41 2c 30 78 34 41 2c 30 78 34 37 2c 0a 09 09  EA,0x4A,0x47,...
0620: 30 78 36 41 2c 30 78 33 36 2c 30 78 33 37 2c 30  0x6A,0x36,0x37,0
0630: 78 37 35 2c 30 78 42 39 2c 30 78 38 45 2c 30 78  x75,0xB9,0x8E,0x
0640: 46 35 2c 30 78 35 46 2c 30 78 36 37 2c 30 78 43  F5,0x5F,0x67,0xC
0650: 46 2c 30 78 31 46 2c 30 78 44 38 2c 0a 09 09 30  F,0x1F,0xD8,...0
0660: 78 43 41 2c 30 78 37 30 2c 30 78 34 32 2c 30 78  xCA,0x70,0x42,0x
0670: 43 37 2c 30 78 41 32 2c 30 78 45 44 2c 30 78 30  C7,0xA2,0xED,0x0
0680: 46 2c 30 78 37 44 2c 30 78 42 45 2c 30 78 34 33  F,0x7D,0xBE,0x43
0690: 2c 30 78 30 38 2c 30 78 32 38 2c 0a 09 09 30 78  ,0x08,0x28,...0x
06a0: 36 36 2c 30 78 33 44 2c 30 78 44 44 2c 30 78 38  66,0x3D,0xDD,0x8
06b0: 37 2c 30 78 30 44 2c 30 78 36 31 2c 30 78 36 45  7,0x0D,0x61,0x6E
06c0: 2c 30 78 44 30 2c 30 78 45 37 2c 30 78 34 39 2c  ,0xD0,0xE7,0x49,
06d0: 30 78 44 31 2c 30 78 37 30 2c 0a 09 09 30 78 41  0xD1,0x70,...0xA
06e0: 39 2c 30 78 34 44 2c 30 78 44 35 2c 30 78 46 44  9,0x4D,0xD5,0xFD
06f0: 2c 30 78 45 44 2c 30 78 46 32 2c 30 78 36 44 2c  ,0xED,0xF2,0x6D,
0700: 30 78 33 32 2c 30 78 31 37 2c 30 78 39 37 2c 30  0x32,0x17,0x97,0
0710: 78 35 42 2c 30 78 30 36 2c 0a 09 09 30 78 36 30  x5B,0x06,...0x60
0720: 2c 30 78 39 43 2c 30 78 35 46 2c 30 78 41 33 2c  ,0x9C,0x5F,0xA3,
0730: 30 78 35 44 2c 30 78 33 34 2c 30 78 31 34 2c 30  0x5D,0x34,0x14,0
0740: 78 37 45 2c 30 78 36 33 2c 30 78 35 34 2c 30 78  x7E,0x63,0x54,0x
0750: 45 34 2c 30 78 37 45 2c 0a 09 09 30 78 30 39 2c  E4,0x7E,...0x09,
0760: 30 78 38 46 2c 30 78 42 42 2c 30 78 38 45 2c 30  0x8F,0xBB,0x8E,0
0770: 78 41 30 2c 30 78 44 30 2c 30 78 39 36 2c 30 78  xA0,0xD0,0x96,0x
0780: 41 43 2c 30 78 33 30 2c 30 78 32 30 2c 30 78 33  AC,0x30,0x20,0x3
0790: 39 2c 30 78 33 42 2c 0a 09 09 30 78 38 43 2c 30  9,0x3B,...0x8C,0
07a0: 78 39 32 2c 30 78 36 35 2c 30 78 33 37 2c 30 78  x92,0x65,0x37,0x
07b0: 30 41 2c 30 78 38 46 2c 30 78 45 43 2c 30 78 37  0A,0x8F,0xEC,0x7
07c0: 32 2c 30 78 38 42 2c 30 78 36 31 2c 30 78 37 44  2,0x8B,0x61,0x7D
07d0: 2c 30 78 36 32 2c 0a 09 09 30 78 32 34 2c 30 78  ,0x62,...0x24,0x
07e0: 35 34 2c 30 78 45 39 2c 30 78 31 44 2c 30 78 30  54,0xE9,0x1D,0x0
07f0: 31 2c 30 78 36 38 2c 30 78 38 39 2c 30 78 43 34  1,0x68,0x89,0xC4
0800: 2c 30 78 37 42 2c 30 78 33 43 2c 30 78 34 38 2c  ,0x7B,0x3C,0x48,
0810: 30 78 36 32 2c 0a 09 09 30 78 39 42 2c 30 78 38  0x62,...0x9B,0x8
0820: 33 2c 30 78 31 31 2c 30 78 33 41 2c 30 78 30 42  3,0x11,0x3A,0x0B
0830: 2c 30 78 30 44 2c 30 78 45 46 2c 30 78 35 41 2c  ,0x0D,0xEF,0x5A,
0840: 30 78 45 34 2c 30 78 37 41 2c 30 78 41 30 2c 30  0xE4,0x7A,0xA0,0
0850: 78 36 39 2c 0a 09 09 30 78 46 34 2c 30 78 35 34  x69,...0xF4,0x54
0860: 2c 30 78 42 35 2c 30 78 35 42 2c 0a 09 7d 3b 0a  ,0xB5,0x5B,..};.
0870: 09 73 74 61 74 69 63 20 75 6e 73 69 67 6e 65 64  .static unsigned
0880: 20 63 68 61 72 20 64 68 67 5f 32 30 34 38 5b 5d   char dhg_2048[]
0890: 20 3d 20 7b 0a 09 09 30 78 30 32 2c 0a 09 7d 3b   = {...0x02,..};
08a0: 0a 0a 09 44 48 20 2a 64 68 20 3d 20 44 48 5f 6e  ...DH *dh = DH_n
08b0: 65 77 28 29 3b 3b 0a 09 42 49 47 4e 55 4d 20 2a  ew();;..BIGNUM *
08c0: 64 68 70 5f 62 6e 2c 20 2a 64 68 67 5f 62 6e 3b  dhp_bn, *dhg_bn;
08d0: 0a 0a 09 69 66 20 28 64 68 20 3d 3d 20 4e 55 4c  ...if (dh == NUL
08e0: 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 20 4e 55  L) {...return NU
08f0: 4c 4c 3b 0a 09 7d 0a 0a 09 64 68 70 5f 62 6e 20  LL;..}...dhp_bn 
0900: 3d 20 42 4e 5f 62 69 6e 32 62 6e 28 64 68 70 5f  = BN_bin2bn(dhp_
0910: 32 30 34 38 2c 20 73 69 7a 65 6f 66 20 28 64 68  2048, sizeof (dh
0920: 70 5f 32 30 34 38 29 2c 20 4e 55 4c 4c 29 3b 0a  p_2048), NULL);.
0930: 09 64 68 67 5f 62 6e 20 3d 20 42 4e 5f 62 69 6e  .dhg_bn = BN_bin
0940: 32 62 6e 28 64 68 67 5f 32 30 34 38 2c 20 73 69  2bn(dhg_2048, si
0950: 7a 65 6f 66 20 28 64 68 67 5f 32 30 34 38 29 2c  zeof (dhg_2048),
0960: 20 4e 55 4c 4c 29 3b 0a 0a 23 69 66 64 65 66 20   NULL);..#ifdef 
0970: 54 43 4c 54 4c 53 5f 4f 50 45 4e 53 53 4c 5f 50  TCLTLS_OPENSSL_P
0980: 52 45 5f 31 5f 31 5f 41 50 49 0a 09 64 68 2d 3e  RE_1_1_API..dh->
0990: 70 20 3d 20 64 68 70 5f 62 6e 3b 0a 09 64 68 2d  p = dhp_bn;..dh-
09a0: 3e 67 20 3d 20 64 68 67 5f 62 6e 3b 0a 0a 09 69  >g = dhg_bn;...i
09b0: 66 20 28 64 68 70 5f 62 6e 20 3d 3d 20 4e 55 4c  f (dhp_bn == NUL
09c0: 4c 20 7c 7c 20 64 68 67 5f 62 6e 20 3d 3d 20 4e  L || dhg_bn == N
09d0: 55 4c 4c 29 20 7b 0a 23 65 6c 73 65 0a 09 69 66  ULL) {.#else..if
09e0: 20 28 64 68 70 5f 62 6e 20 3d 3d 20 4e 55 4c 4c   (dhp_bn == NULL
09f0: 20 7c 7c 20 64 68 67 5f 62 6e 20 3d 3d 20 4e 55   || dhg_bn == NU
0a00: 4c 4c 20 7c 7c 20 21 44 48 5f 73 65 74 30 5f 70  LL || !DH_set0_p
0a10: 71 67 28 64 68 2c 20 64 68 70 5f 62 6e 2c 20 4e  qg(dh, dhp_bn, N
0a20: 55 4c 4c 2c 20 64 68 67 5f 62 6e 29 29 20 7b 0a  ULL, dhg_bn)) {.
0a30: 23 65 6e 64 69 66 0a 09 09 44 48 5f 66 72 65 65  #endif...DH_free
0a40: 28 64 68 29 3b 0a 09 09 42 4e 5f 66 72 65 65 28  (dh);...BN_free(
0a50: 64 68 70 5f 62 6e 29 3b 0a 09 09 42 4e 5f 66 72  dhp_bn);...BN_fr
0a60: 65 65 28 64 68 67 5f 62 6e 29 3b 0a 09 09 72 65  ee(dhg_bn);...re
0a70: 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a  turn(NULL);..}..
0a80: 09 72 65 74 75 72 6e 28 64 68 29 3b 0a 7d 0a 5f  .return(dh);.}._
0a90: 45 4f 46 5f 0a 7d 0a 0a 23 20 45 6e 61 62 6c 65  EOF_.}..# Enable
0aa0: 20 73 75 70 70 6f 72 74 20 66 6f 72 20 67 69 76   support for giv
0ab0: 69 6e 67 20 74 68 65 20 73 61 6d 65 20 44 48 20  ing the same DH 
0ac0: 70 61 72 61 6d 73 20 65 61 63 68 20 74 69 6d 65  params each time
0ad0: 0a 69 66 20 5b 20 22 24 31 22 20 3d 20 27 66 61  .if [ "$1" = 'fa
0ae0: 6c 6c 62 61 63 6b 27 20 5d 3b 20 74 68 65 6e 0a  llback' ]; then.
0af0: 09 67 65 6e 5f 64 68 5f 70 61 72 61 6d 73 5f 66  .gen_dh_params_f
0b00: 61 6c 6c 62 61 63 6b 20 26 26 20 65 78 69 74 20  allback && exit 
0b10: 30 0a 0a 09 65 78 69 74 20 31 0a 66 69 0a 0a 67  0...exit 1.fi..g
0b20: 65 6e 5f 64 68 5f 70 61 72 61 6d 73 5f 6f 70 65  en_dh_params_ope
0b30: 6e 73 73 6c 20 26 26 20 65 78 69 74 20 30 0a 67  nssl && exit 0.g
0b40: 65 6e 5f 64 68 5f 70 61 72 61 6d 73 5f 72 65 6d  en_dh_params_rem
0b50: 6f 74 65 20 26 26 20 65 78 69 74 20 30 0a 67 65  ote && exit 0.ge
0b60: 6e 5f 64 68 5f 70 61 72 61 6d 73 5f 66 61 6c 6c  n_dh_params_fall
0b70: 62 61 63 6b 20 26 26 20 65 78 69 74 20 30 0a 0a  back && exit 0..
0b80: 65 78 69 74 20 31 0a                             exit 1.