Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tahoe-ssk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
PrivateStorage
tahoe-ssk
Commits
9aaabbec
Commit
9aaabbec
authored
May 12, 2023
by
Jean-Paul Calderone
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/main' into 5.decoding-and-decryption
parents
8d4203de
3045b8d4
No related branches found
No related tags found
1 merge request
!7
Implement enough encryption and encoding to be able to read plaintext from Tahoe-LAFS-generated SDMF shares
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Tahoe/SDMF.hs
+16
-8
16 additions, 8 deletions
src/Tahoe/SDMF.hs
src/Tahoe/SDMF/Internal/Capability.hs
+10
-34
10 additions, 34 deletions
src/Tahoe/SDMF/Internal/Capability.hs
src/Tahoe/SDMF/Internal/Keys.hs
+5
-0
5 additions, 0 deletions
src/Tahoe/SDMF/Internal/Keys.hs
with
31 additions
and
42 deletions
src/Tahoe/SDMF.hs
+
16
−
8
View file @
9aaabbec
-- | Expose the library's public interface.
module
Tahoe.SDMF
(
Share
(
..
),
Writer
(
..
),
Reader
(
..
),
encode
,
decode
,
module
Tahoe
.
SDMF
.
Internal
.
Share
,
module
Tahoe
.
SDMF
.
Internal
.
Capability
,
module
Tahoe
.
SDMF
.
Internal
.
Encoding
,
)
where
import
Tahoe.SDMF.Internal.Capability
import
Tahoe.SDMF.Internal.Encoding
import
Tahoe.SDMF.Internal.Share
import
Tahoe.SDMF.Internal.Capability
(
Reader
(
..
),
Writer
(
..
),
)
import
Tahoe.SDMF.Internal.Encoding
(
decode
,
encode
,
)
import
Tahoe.SDMF.Internal.Share
(
Reader
(
..
),
Share
(
..
),
Writer
(
..
),
)
This diff is collapsed.
Click to expand it.
src/Tahoe/SDMF/Internal/Capability.hs
+
10
−
34
View file @
9aaabbec
-- | Structured representations of SDMF capabilities.
module
Tahoe.SDMF.Internal.Capability
where
import
Crypto.Cipher.AES128
(
AESKey128
)
import
Crypto.Classes
(
buildKey
)
import
Crypto.Types
(
IV
)
import
Prelude
hiding
(
Read
)
import
qualified
Data.ByteString
as
B
import
Data.Serialize
(
encode
)
import
Tahoe.CHK.Crypto
(
taggedHash
,
taggedPairHash
)
import
Tahoe.SDMF.Internal.Keys
(
Read
,
Write
)
-- | A read capability for an SDMF object.
data
Reader
=
Reader
{
readerReadKey
::
B
.
ByteString
{
readerReadKey
::
Read
,
readerVerificationKeyHash
::
B
.
ByteString
}
deriving
(
Show
)
-- | A write capability for an SDMF object.
data
Writer
=
Writer
{
writerWriteKey
::
AESKey128
{
writerWriteKey
::
Write
,
writerReader
::
Reader
}
deriveReader
::
AESKey128
->
B
.
ByteString
->
Reader
deriveReader
writeKey
readerVerificationKeyHash
=
Reader
{
..
}
where
readerReadKey
=
taggedHash
readKeyLength
mutableReadKeyTag
(
encode
writeKey
)
readKeyLength
::
Int
readKeyLength
=
32
mutableReadKeyTag
::
B
.
ByteString
mutableReadKeyTag
=
"allmydata_mutable_writekey_to_readkey_v1"
{- | Compute the encryption (and decryption) key used to convert the
application payload plaintext to ciphertext and back again.
-}
deriveEncryptionKey
::
MonadFail
m
=>
Reader
->
IV
AESKey128
->
m
AESKey128
deriveEncryptionKey
Reader
{
readerReadKey
}
iv
=
do
let
k
=
buildKey
$
taggedPairHash
encryptionKeyLength
mutableDataKeyTag
readerReadKey
(
encode
iv
)
case
k
of
Nothing
->
fail
"Could not build AESKey128 when deriving encryption key"
Just
key
->
pure
key
mutableDataKeyTag
::
B
.
ByteString
mutableDataKeyTag
=
"allmydata_mutable_readkey_to_datakey_v1"
encryptionKeyLength
::
Int
encryptionKeyLength
=
16
deriving
(
Show
)
This diff is collapsed.
Click to expand it.
src/Tahoe/SDMF/Internal/Keys.hs
+
5
−
0
View file @
9aaabbec
...
...
@@ -34,10 +34,15 @@ newtype Signature = Signature {unSignature :: RSA.PrivateKey}
deriving
newtype
(
Eq
,
Show
)
data
Write
=
Write
{
unWrite
::
AES128
,
writeKeyBytes
::
ByteArray
.
ScrubbedBytes
}
instance
Show
Write
where
show
(
Write
_
bs
)
=
T
.
unpack
$
T
.
concat
[
"<WriteKey "
,
encodeBase32Unpadded
(
ByteArray
.
convert
bs
),
">"
]
data
Read
=
Read
{
unRead
::
AES128
,
readKeyBytes
::
ByteArray
.
ScrubbedBytes
}
instance
Show
Read
where
show
(
Read
_
bs
)
=
T
.
unpack
$
T
.
concat
[
"<ReadKey "
,
encodeBase32Unpadded
(
ByteArray
.
convert
bs
),
">"
]
newtype
StorageIndex
=
StorageIndex
{
unStorageIndex
::
B
.
ByteString
}
newtype
WriteEnablerMaster
=
WriteEnablerMaster
ByteArray
.
ScrubbedBytes
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment