-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
generate_config_with_secure_cookie.sh
executable file
·62 lines (47 loc) · 1.62 KB
/
generate_config_with_secure_cookie.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
exec scala "$0" "$@"
!#
/**
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
*/
import java.security.{MessageDigest, SecureRandom}
object Crypt {
val hex = "0123456789ABCDEF"
val lineSeparator = System.getProperty("line.separator")
lazy val random = SecureRandom.getInstance("SHA1PRNG")
def md5(text: String): String = md5(unifyLineSeparator(text).getBytes("ASCII"))
def md5(bytes: Array[Byte]): String = digest(bytes, MessageDigest.getInstance("MD5"))
def sha1(text: String): String = sha1(unifyLineSeparator(text).getBytes("ASCII"))
def sha1(bytes: Array[Byte]): String = digest(bytes, MessageDigest.getInstance("SHA1"))
def generateSecureCookie: String = {
val bytes = Array.fill(32)(0.byteValue)
random.nextBytes(bytes)
sha1(bytes)
}
def digest(bytes: Array[Byte], md: MessageDigest): String = {
md.update(bytes)
hexify(md.digest)
}
def hexify(bytes: Array[Byte]): String = {
val builder = new StringBuilder
bytes.foreach { byte => builder.append(hex.charAt((byte & 0xF) >> 4)).append(hex.charAt(byte & 0xF)) }
builder.toString
}
private def unifyLineSeparator(text: String): String = text.replaceAll(lineSeparator, "\n")
}
print("""
# This config imports the Akka reference configuration.
include "akka-reference.conf"
# In this file you can override any option defined in the 'akka-reference.conf' file.
# Copy in all or parts of the 'akka-reference.conf' file and modify as you please.
akka {
remote {
netty {
secure-cookie = """")
print(Crypt.generateSecureCookie)
print(""""
require-cookie = on
}
}
}
""")