Skip to content

Commit 4d11d00

Browse files
authored
chore: API docs website and release-ready docs (#21)
2 parents 17ba096 + ea9596b commit 4d11d00

21 files changed

+136
-14
lines changed

.github/workflows/integration.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ jobs:
1515
- uses: "docker://ghcr.io/sethvargo/ratchet@sha256:81af1075dc4ceb54f1c87ac9ff6a9ebe43626c59913f01810f5be77f4eb67301" # ratchet:docker://ghcr.io/sethvargo/ratchet:0.4.0
1616
with:
1717
args: "check .github/workflows/codeql.yml"
18+
- uses: "docker://ghcr.io/sethvargo/ratchet@sha256:81af1075dc4ceb54f1c87ac9ff6a9ebe43626c59913f01810f5be77f4eb67301" # ratchet:docker://ghcr.io/sethvargo/ratchet:0.4.0
19+
with:
20+
args: "check .github/workflows/release.yml"
21+
- uses: "docker://ghcr.io/sethvargo/ratchet@sha256:81af1075dc4ceb54f1c87ac9ff6a9ebe43626c59913f01810f5be77f4eb67301" # ratchet:docker://ghcr.io/sethvargo/ratchet:0.4.0
22+
with:
23+
args: "check .github/workflows/pages.yml"
1824
build:
1925
runs-on: ubuntu-latest
2026
steps:

.github/workflows/pages.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Pages
2+
on:
3+
release:
4+
types: [published]
5+
workflow_dispatch:
6+
permissions:
7+
contents: read
8+
pages: write
9+
id-token: write
10+
concurrency:
11+
group: pages
12+
cancel-in-progress: false
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-latest
16+
environment:
17+
name: pages
18+
url: ${{ steps.deployment.outputs.page_url }}
19+
steps:
20+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # ratchet:actions/checkout@v3
21+
- uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # ratchet:actions/setup-java@v3
22+
with:
23+
distribution: zulu
24+
java-version: 8
25+
- uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 # ratchet:gradle/gradle-build-action@v2
26+
- run: ./gradlew dokkaHtml
27+
- uses: actions/configure-pages@f156874f8191504dae5b037505266ed5dda6c382 # ratchet:actions/configure-pages@v3
28+
- run: |
29+
mkdir -p _site
30+
mv build/dokka/html _site/api
31+
- uses: actions/upload-pages-artifact@66b63f4a7de003f4f00cc8e9af4b83b8f2abdb96 # ratchet:actions/upload-pages-artifact@v1
32+
- uses: actions/deploy-pages@ee48c7b82e077d7b8ef30b50a719e6a792a50c9a # ratchet:actions/deploy-pages@v2
33+
id: deployment

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Noise for Kotlin
22

3-
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/nl.sanderdijkhuis/noise-kotlin/badge.svg?style=flat-square&gav=true)](https://maven-badges.herokuapp.com/maven-central/nl.sanderdijkhuis/noise-kotlin)
3+
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/nl.sanderdijkhuis/noise-kotlin/badge.svg?style=flat-square&gav=true)](https://central.sonatype.com/artifact/nl.sanderdijkhuis/noise-kotlin/)
44

5-
**Noise for Kotlin** contains example code for implementing [Noise](https://noiseprotocol.org) protocols based on Diffie-Hellman key agreement. It may evolve into a usable library. [Contact me](mailto:mail@sanderdijkhuis.nl) if you are interested in helping out to realize this.
5+
**Noise for Kotlin** enables implementation of [Noise](https://noiseprotocol.org) protocols based on Diffie-Hellman key agreement.
66

7-
> **Warning**: Some reasons why you **may not** use any of this code in production yet:
8-
>
9-
> - It has not yet been reviewed for secure engineering practices.
10-
> - It leaves your secrets on the heap, up for grabs.
7+
## API documentation
8+
9+
See the [API docs](https://sander.github.io/noise-kotlin/api/) about the latest release or use the Gradle `dokkaHtml` task for a local copy about any version.
1110

1211
## How to build
1312

@@ -36,7 +35,9 @@ Then, implement [`Cryptography`](src/main/kotlin/cryptography/Cryptography.kt) f
3635
- Support only Curve25519, ChaCha20-Poly1305, and SHA-256 to reduce the need to choose and since these are available on most platforms.
3736
- Consequence: it should be easy to use with [Kotlin Multiplatform](https://kotlinlang.org/docs/multiplatform.html).
3837
- Use only Kotlin types and functions, and nothing directly from Java SE or libraries.
39-
- Consequence: all dangerous cryptography implementation is behind an interface, which users need to implement using native platform functions.
38+
- Consequence: all cryptographic function dependency implementation is behind an interface, which users need to implement using native platform functions.
39+
- Do not include particular masking, encryption, or zeroization functionality for sensitive data, to avoid disproportional complexity.
40+
- Consequence: run with sufficiently protected volatile memory and protect heap dump data from unauthorized access.
4041

4142
## Test vectors
4243

SECURITY.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# Security policy
22

3-
> **Warning**: Do not use this code in production. Expect vulnerabilities. See the [README](README.md) for details.
4-
53
## Supported versions
64

7-
Currently only pre-release and snapshot versions are available. Any vulnerability should be mitigated in a next pre-release version.
5+
Currently only the latest (pre-)release version is maintained. Any vulnerability should be mitigated in a next pre-release version.
86

97
## Reporting a vulnerability
108

build.gradle.kts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.net.URL
2+
import org.jetbrains.dokka.gradle.DokkaTask
13
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
24

35
plugins {
@@ -7,6 +9,7 @@ plugins {
79
`maven-publish`
810
signing
911
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
12+
id("org.jetbrains.dokka") version "1.8.20"
1013
}
1114

1215
group = "nl.sanderdijkhuis"
@@ -42,6 +45,21 @@ tasks.test {
4245
useJUnitPlatform()
4346
}
4447

48+
tasks.withType<DokkaTask> {
49+
dokkaSourceSets {
50+
named("main") {
51+
moduleName.set("Noise for Kotlin")
52+
includes.from("src/main/README.md")
53+
skipDeprecated.set(true)
54+
sourceLink {
55+
localDirectory.set(file("src/main/kotlin"))
56+
remoteUrl.set(URL("https://github.com/sander/noise-kotlin/tree/main/src/main/kotlin"))
57+
remoteLineSuffix.set("#L")
58+
}
59+
}
60+
}
61+
}
62+
4563
tasks.withType<KotlinCompile> {
4664
kotlinOptions.allWarningsAsErrors = true
4765
kotlinOptions.jvmTarget = "1.8"

src/main/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Module Noise for Kotlin
2+
3+
A library for implementing [Noise](https://noiseprotocol.org) protocols based on Diffie-Hellman key agreement.
4+
5+
To get started, implement the cryptography dependencies and initialize a Noise handshake.
6+
7+
# Package nl.sanderdijkhuis.noise
8+
9+
Provides Noise Protocol Framework implementation.
10+
11+
# Package nl.sanderdijkhuis.noise.data
12+
13+
Provides management of generic bounded binary data and state.
14+
15+
All data is handled as immutable.
16+
17+
No particular masking, encryption, or zeroization of sensitive data is implemented. The module assumes that the runtime environment’s volatile memory is sufficiently protected and that only trusted roles can access heap dump data.
18+
19+
# Package nl.sanderdijkhuis.noise.cryptography
20+
21+
Provides means to implement and apply cryptographic function dependencies.
22+
23+
The module depends on the following cryptographic functions:
24+
25+
- ChaCha20-Poly1305 Authenticated Encryption with Associated Data (AEAD) from [RFC 8439](https://www.rfc-editor.org/rfc/rfc8439.html)
26+
- SHA-256 hashing from [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf)
27+
- X25519 Diffie-Hellman exchange from [RFC 7748](https://www.rfc-editor.org/rfc/rfc7748)
28+
29+
These can be implemented using for example Java SE 11 or [Bouncy Castle](https://www.bouncycastle.org/java.html).
30+
31+
Note that in some cases we speak of “no-op encryption”. This is to meet the `EncryptWithAd` and `DecryptWithAd` [Noise specification](https://noiseprotocol.org/noise.html#the-cipherstate-object) which provide the identity function when no cipher key is set.

src/main/kotlin/Cipher.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package nl.sanderdijkhuis.noise
33
import nl.sanderdijkhuis.noise.cryptography.*
44
import nl.sanderdijkhuis.noise.data.State
55

6+
/** Encompasses all Noise protocol cipher state required to encrypt and decrypt data. */
67
data class Cipher(val cryptography: Cryptography, val key: CipherKey? = null, val nonce: Nonce = Nonce.zero) {
78

89
fun encrypt(associatedData: AssociatedData, plaintext: Plaintext): State<Cipher, Ciphertext> =
@@ -18,4 +19,4 @@ data class Cipher(val cryptography: Cryptography, val key: CipherKey? = null, va
1819
cryptography.decrypt(it, nonce, associatedData, ciphertext)?.let { p -> State(copy(nonce = n), p) }
1920
} ?: State(this, ciphertext.plaintext)
2021
}
21-
}
22+
}

src/main/kotlin/Handshake.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import nl.sanderdijkhuis.noise.data.Data
88
import nl.sanderdijkhuis.noise.data.Size
99
import nl.sanderdijkhuis.noise.data.State
1010

11+
/**
12+
* Encompasses all Noise protocol handshake state required to read and write messages.
13+
*
14+
* Start with [initialize], supplying one of the implemented patterns:
15+
*
16+
* - [Noise_NK_25519_ChaChaPoly_SHA256]
17+
* - [Noise_XN_25519_ChaChaPoly_SHA256]
18+
*
19+
* Proposals to add more patterns or generate correct patterns dynamically are welcomed.
20+
*/
1121
data class Handshake(
1222
val role: Role,
1323
val symmetry: Symmetry,
@@ -19,12 +29,14 @@ data class Handshake(
1929
val trustedStaticKeys: Set<PublicKey> = emptySet()
2030
) : MessageType {
2131

32+
/** A handshake pattern. */
2233
data class Pattern(
2334
val name: String,
2435
val preSharedMessagePatterns: List<List<Token>>,
2536
val messagePatterns: List<List<Token>>
2637
)
2738

39+
/** Message pattern token, indicating which keys are sent and which key agreements are performed. */
2840
enum class Token {
2941
E, S, EE, ES, SE, SS
3042
}
@@ -37,6 +49,7 @@ data class Handshake(
3749
private fun State<Handshake, Data>.append(f: (Symmetry) -> State<Symmetry, Data>?) =
3850
f(value.symmetry)?.let { s -> State(value.copy(symmetry = s.value), result + s.result) }
3951

52+
/** Returns a handshake message only if this is appropriate given the pattern and state. */
4053
fun writeMessage(payload: Payload): State<out MessageType, Data>? =
4154
messagePatterns.first().fold(State(this, Data.empty) as State<Handshake, Data>?) { state, token ->
4255
state?.let { s ->
@@ -64,6 +77,7 @@ data class Handshake(
6477
else State(s.value.copy(messagePatterns = rest), s.result)
6578
}
6679

80+
/** Returns a handshake message payload only if this is appropriate given the pattern and state. */
6781
fun readMessage(data: Data): State<out MessageType, Payload>? =
6882
messagePatterns.first().fold(State(this, data) as State<Handshake, Data>?) { state, token ->
6983
state?.let { s ->
@@ -108,6 +122,7 @@ data class Handshake(
108122

109123
companion object {
110124

125+
/** Returns initial handshake state only if sufficient keys are provided. */
111126
fun initialize(
112127
cryptography: Cryptography,
113128
pattern: Pattern,

src/main/kotlin/Payload.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ package nl.sanderdijkhuis.noise
22

33
import nl.sanderdijkhuis.noise.data.Data
44

5+
/** Plaintext handshake payload. */
56
@JvmInline
67
value class Payload(val data: Data)

src/main/kotlin/Role.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package nl.sanderdijkhuis.noise
22

3+
/** The role of the user holding the handshake state. The initiator is the one who sends the first message. */
34
enum class Role {
45
INITIATOR, RESPONDER
56
}

0 commit comments

Comments
 (0)