Skip to content

Commit

Permalink
Directory,Tests: remove janky pem reader
Browse files Browse the repository at this point in the history
This commit removes janky pem reader code
in favour of Bouncycastle's PemReader.
  • Loading branch information
aarani committed Apr 25, 2023
1 parent 128b6a3 commit fdc84a1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 40 deletions.
15 changes: 5 additions & 10 deletions NOnion/Directory/HiddenServiceDescriptorDocument.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ type IntroductionPointEntry =
let words = lines.Peek().Split ' ' |> MutableQueue<string>

let rec readBlock(state: string) =
let line = lines.Dequeue()
let line = sprintf "%s\n" (lines.Dequeue())

if line.StartsWith "-----END" then
state
state + line
else
readBlock(state + line)

Expand Down Expand Up @@ -73,28 +73,23 @@ type IntroductionPointEntry =
}
| "auth-key" ->
lines.Dequeue() |> ignore<string>
//get rid of begin
lines.Dequeue() |> ignore<string>

innerParse
{ state with
AuthKey =
readBlock String.Empty
|> Convert.FromBase64String
|> PemUtility.PemToByteArray
|> Certificate.FromBytes
|> Some
}
| "enc-key-cert" ->
lines.Dequeue() |> ignore<string>
//get rid of begin
lines.Dequeue() |> ignore<string>


innerParse
{ state with
EncKeyCert =
readBlock String.Empty
|> Convert.FromBase64String
|> PemUtility.PemToByteArray
|> Certificate.FromBytes
|> Some
}
Expand Down Expand Up @@ -211,7 +206,7 @@ type HiddenServiceDescriptorDocument =
let lines = stringToParse.Split '\n' |> MutableQueue<string>

let rec readBlock(state: string) =
let line = lines.Dequeue()
let line = sprintf "%s\n" (lines.Dequeue())

if line.StartsWith "-----END" then
state + line
Expand Down
25 changes: 5 additions & 20 deletions NOnion/Directory/HiddenServiceFirstLayerDescriptorDocument.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type HiddenServiceFirstLayerDescriptorDocument =
let lines = stringToParse.Split '\n' |> MutableQueue<string>

let rec readBlock(state: string) =
let line = lines.Dequeue()
let line = sprintf "%s\n" (lines.Dequeue())

if line.StartsWith "-----END" then
state + line
Expand Down Expand Up @@ -153,16 +153,8 @@ type HiddenServiceFirstLayerDescriptorDocument =

{ state with
HiddenServiceFirstLayerDescriptorDocument.SigningKeyCert =
(readBlock String.Empty)
.Replace(
"-----BEGIN ED25519 CERT-----",
String.Empty
)
.Replace(
"-----END ED25519 CERT-----",
String.Empty
)
|> Convert.FromBase64String
readBlock String.Empty
|> PemUtility.PemToByteArray
|> Certificate.FromBytes
|> Some
}
Expand All @@ -176,17 +168,10 @@ type HiddenServiceFirstLayerDescriptorDocument =
| "superencrypted" ->
lines.Dequeue() |> ignore<string>

let payloadString = readBlock String.Empty

{ state with
HiddenServiceFirstLayerDescriptorDocument.EncryptedPayload =
payloadString
.Replace(
"-----BEGIN MESSAGE-----",
String.Empty
)
.Replace("-----END MESSAGE-----", String.Empty)
|> Convert.FromBase64String
readBlock String.Empty
|> PemUtility.PemToByteArray
|> Some
}
| _ ->
Expand Down
13 changes: 3 additions & 10 deletions NOnion/Directory/HiddenServiceSecondLayerDescriptorDocument.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type HiddenServiceSecondLayerDescriptorDocument =
let lines = stringToParse.Split '\n' |> MutableQueue<string>

let rec readBlock(state: string) =
let line = lines.Dequeue()
let line = sprintf "%s\n" (lines.Dequeue())

if line.StartsWith "-----END" then
state + line
Expand All @@ -40,17 +40,10 @@ type HiddenServiceSecondLayerDescriptorDocument =
| "encrypted" ->
lines.Dequeue() |> ignore<string>

let payloadString = readBlock String.Empty

{ state with
HiddenServiceSecondLayerDescriptorDocument.EncryptedPayload =
payloadString
.Replace(
"-----BEGIN MESSAGE-----",
String.Empty
)
.Replace("-----END MESSAGE-----", String.Empty)
|> Convert.FromBase64String
readBlock String.Empty
|> PemUtility.PemToByteArray
|> Some
}
| _ ->
Expand Down

0 comments on commit fdc84a1

Please sign in to comment.