hackage-security-0.6.2.4: Hackage security library
Safe HaskellNone
LanguageHaskell2010

Hackage.Security.Client

Description

Main entry point into the Hackage Security framework for clients

Synopsis

Checking for updates

checkForUpdates Source #

Arguments

:: forall (down :: Type -> Type). (Throws VerificationError, Throws SomeRemoteError) 
=> Repository down 
-> Maybe UTCTime

To check expiry times against (if using)

-> IO HasUpdates 

Generic logic for checking if there are updates

This implements the logic described in Section 5.1, "The client application", of the TUF spec. It checks which of the server metadata has changed, and downloads all changed metadata to the local cache. (Metadata here refers both to the TUF security metadata as well as the Hackage package index.)

You should pass Nothing for the UTCTime _only_ under exceptional circumstances (such as when the main server is down for longer than the expiry dates used in the timestamp files on mirrors).

Downloading targets

downloadPackage Source #

Arguments

:: forall (down :: Type -> Type). (Throws SomeRemoteError, Throws VerificationError, Throws InvalidPackageException) 
=> Repository down

Repository

-> PackageIdentifier

Package to download

-> Path Absolute

Destination (see also downloadPackage')

-> IO () 

Download a package

downloadPackage' Source #

Arguments

:: forall (down :: Type -> Type). (Throws SomeRemoteError, Throws VerificationError, Throws InvalidPackageException) 
=> Repository down

Repository

-> PackageIdentifier

Package to download

-> FilePath

Destination

-> IO () 

Variation on downloadPackage that takes a FilePath instead.

Access to the Hackage index

data Directory Source #

Index directory

Constructors

Directory 

Fields

newtype DirectoryEntry Source #

Entry into the Hackage index.

Constructors

DirectoryEntry 

Fields

  • directoryEntryBlockNo :: TarEntryOffset

    (Low-level) block number of the tar index entry

    Exposed for the benefit of clients who read the .tar file directly. For this reason also the Show and Read instances for DirectoryEntry just print and parse the underlying TarEntryOffset.

getDirectory :: forall (down :: Type -> Type). Repository down -> IO Directory Source #

Read the Hackage index directory

Should only be called after checkForUpdates.

data IndexFile a where Source #

Files that we might request from the index

The type index tells us the type of the decoded file, if any. For files for which the library does not support decoding this will be (). NOTE: Clients should NOT rely on this type index being (), or they might break if we add support for parsing additional file formats in the future.

TODO: If we wanted to support legacy Hackage, we should also have a case for the global preferred-versions file. But supporting legacy Hackage will probably require more work anyway..

Instances

Instances details
SomePretty IndexFile Source # 
Instance details

Defined in Hackage.Security.TUF.Layout.Index

SomeShow IndexFile Source # 
Instance details

Defined in Hackage.Security.TUF.Layout.Index

Show (IndexFile dec) Source # 
Instance details

Defined in Hackage.Security.TUF.Layout.Index

Methods

showsPrec :: Int -> IndexFile dec -> ShowS #

show :: IndexFile dec -> String #

showList :: [IndexFile dec] -> ShowS #

Pretty (IndexFile dec) Source # 
Instance details

Defined in Hackage.Security.TUF.Layout.Index

Methods

pretty :: IndexFile dec -> String Source #

data IndexEntry dec Source #

Entry from the Hackage index; see withIndex.

Constructors

IndexEntry 

Fields

data IndexCallbacks Source #

Various operations that we can perform on the index once its open

Note that IndexEntry contains a fields both for the raw file contents and the parsed file contents; clients can choose which to use.

In principle these callbacks will do verification (once we have implemented author signing). Right now they don't need to do that, because the index as a whole will have been verified.

Constructors

IndexCallbacks 

Fields

withIndex :: forall (down :: Type -> Type) a. Repository down -> (IndexCallbacks -> IO a) -> IO a Source #

Look up entries in the Hackage index

This is in withFile style so that clients can efficiently look up multiple files from the index.

Should only be called after checkForUpdates.

Bootstrapping

requiresBootstrap :: forall (down :: Type -> Type). Repository down -> IO Bool Source #

Check if we need to bootstrap (i.e., if we have root info)

bootstrap :: forall (down :: Type -> Type). (Throws SomeRemoteError, Throws VerificationError) => Repository down -> [KeyId] -> KeyThreshold -> IO () Source #

Bootstrap the chain of trust

New clients might need to obtain a copy of the root metadata. This however represents a chicken-and-egg problem: how can we verify the root metadata we downloaded? The only possibility is to be provided with a set of an out-of-band set of root keys and an appropriate threshold.

Clients who provide a threshold of 0 can do an initial "unsafe" update of the root information, if they wish.

The downloaded root information will _only_ be verified against the provided keys, and _not_ against previously downloaded root info (if any). It is the responsibility of the client to call bootstrap only when this is the desired behaviour.

Re-exports

data Signed a Source #

Constructors

Signed 

Fields

Instances

Instances details
MonadKeys m => FromJSON m (Signed Mirrors) Source # 
Instance details

Defined in Hackage.Security.TUF.Mirrors

MonadKeys m => FromJSON m (Signed Root) Source #

We give an instance for Signed Root rather than Root because the key environment from the root data is necessary to resolve the explicit sharing in the signatures.

Instance details

Defined in Hackage.Security.TUF.Root

Methods

fromJSON :: JSValue -> m (Signed Root) Source #

(MonadKeys m, MonadReader RepoLayout m) => FromJSON m (Signed Snapshot) Source # 
Instance details

Defined in Hackage.Security.TUF.Snapshot

MonadKeys m => FromJSON m (Signed Targets) Source # 
Instance details

Defined in Hackage.Security.TUF.Targets

(MonadKeys m, MonadReader RepoLayout m) => FromJSON m (Signed Timestamp) Source # 
Instance details

Defined in Hackage.Security.TUF.Timestamp

(Monad m, ToJSON m a) => ToJSON m (Signed a) Source # 
Instance details

Defined in Hackage.Security.TUF.Signed

Methods

toJSON :: Signed a -> m JSValue Source #

data IndexFile a where Source #

Files that we might request from the index

The type index tells us the type of the decoded file, if any. For files for which the library does not support decoding this will be (). NOTE: Clients should NOT rely on this type index being (), or they might break if we add support for parsing additional file formats in the future.

TODO: If we wanted to support legacy Hackage, we should also have a case for the global preferred-versions file. But supporting legacy Hackage will probably require more work anyway..

Instances

Instances details
SomePretty IndexFile Source # 
Instance details

Defined in Hackage.Security.TUF.Layout.Index

SomeShow IndexFile Source # 
Instance details

Defined in Hackage.Security.TUF.Layout.Index

Show (IndexFile dec) Source # 
Instance details

Defined in Hackage.Security.TUF.Layout.Index

Methods

showsPrec :: Int -> IndexFile dec -> ShowS #

show :: IndexFile dec -> String #

showList :: [IndexFile dec] -> ShowS #

Pretty (IndexFile dec) Source # 
Instance details

Defined in Hackage.Security.TUF.Layout.Index

Methods

pretty :: IndexFile dec -> String Source #

data FileMap Source #

Mapping from paths to file info

File maps are used in target files; the paths are relative to the location of the target files containing the file map.

Instances

Instances details
Show FileMap Source # 
Instance details

Defined in Hackage.Security.TUF.FileMap

ReportSchemaErrors m => FromJSON m FileMap Source # 
Instance details

Defined in Hackage.Security.TUF.FileMap

Monad m => ToJSON m FileMap Source # 
Instance details

Defined in Hackage.Security.TUF.FileMap

Methods

toJSON :: FileMap -> m JSValue Source #

data FileChange Source #

Constructors

FileChanged FileInfo

File got added or modified; we record the new file info

FileDeleted

File got deleted

Instances

Instances details
Show FileChange Source # 
Instance details

Defined in Hackage.Security.TUF.FileMap

data FileInfo Source #

File information

This intentionally does not have an Eq instance; see knownFileInfoEqual and verifyFileInfo instead.

NOTE: Throughout we compute file information always over the raw bytes. For example, when timestamp.json lists the hash of snapshot.json, this hash is computed over the actual snapshot.json file (as opposed to the canonical form of the embedded JSON). This brings it in line with the hash computed over target files, where that is the only choice available.

Instances

Instances details
Show FileInfo Source # 
Instance details

Defined in Hackage.Security.TUF.FileInfo

ReportSchemaErrors m => FromJSON m FileInfo Source # 
Instance details

Defined in Hackage.Security.TUF.FileInfo

Monad m => ToJSON m FileInfo Source # 
Instance details

Defined in Hackage.Security.TUF.FileInfo

Methods

toJSON :: FileInfo -> m JSValue Source #

data Int54 Source #

54-bit integer values

JavaScript can only safely represent numbers between -(2^53 - 1) and 2^53 - 1.

TODO: Although we introduce the type here, we don't actually do any bounds checking and just inherit all type class instance from Int64. We should probably define fromInteger to do bounds checking, give different instances for type classes such as Bounded and FiniteBits, etc.

Instances

Instances details
Data Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Int54 -> c Int54 #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Int54 #

toConstr :: Int54 -> Constr #

dataTypeOf :: Int54 -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Int54) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Int54) #

gmapT :: (forall b. Data b => b -> b) -> Int54 -> Int54 #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Int54 -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Int54 -> r #

gmapQ :: (forall d. Data d => d -> u) -> Int54 -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Int54 -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Int54 -> m Int54 #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Int54 -> m Int54 #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Int54 -> m Int54 #

Storable Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Methods

sizeOf :: Int54 -> Int #

alignment :: Int54 -> Int #

peekElemOff :: Ptr Int54 -> Int -> IO Int54 #

pokeElemOff :: Ptr Int54 -> Int -> Int54 -> IO () #

peekByteOff :: Ptr b -> Int -> IO Int54 #

pokeByteOff :: Ptr b -> Int -> Int54 -> IO () #

peek :: Ptr Int54 -> IO Int54 #

poke :: Ptr Int54 -> Int54 -> IO () #

Bits Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

FiniteBits Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Bounded Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Enum Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Ix Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Num Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Read Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Integral Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Real Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Methods

toRational :: Int54 -> Rational #

Show Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Methods

showsPrec :: Int -> Int54 -> ShowS #

show :: Int54 -> String #

showList :: [Int54] -> ShowS #

PrintfArg Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Eq Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Methods

(==) :: Int54 -> Int54 -> Bool #

(/=) :: Int54 -> Int54 -> Bool #

Ord Int54 Source # 
Instance details

Defined in Text.JSON.Canonical

Methods

compare :: Int54 -> Int54 -> Ordering #

(<) :: Int54 -> Int54 -> Bool #

(<=) :: Int54 -> Int54 -> Bool #

(>) :: Int54 -> Int54 -> Bool #

(>=) :: Int54 -> Int54 -> Bool #

max :: Int54 -> Int54 -> Int54 #

min :: Int54 -> Int54 -> Int54 #

ReportSchemaErrors m => FromJSON m Int54 Source # 
Instance details

Defined in Hackage.Security.Util.JSON

Methods

fromJSON :: JSValue -> m Int54 Source #

Monad m => ToJSON m Int54 Source # 
Instance details

Defined in Hackage.Security.Util.JSON

Methods

toJSON :: Int54 -> m JSValue Source #

data Header Source #

Occasionally it is useful to read only a header from a file.

HeaderOnly intentionally only has a FromJSON instance (no ToJSON).

Instances

Instances details
HasHeader Header Source # 
Instance details

Defined in Hackage.Security.TUF.Header

ReportSchemaErrors m => FromJSON m Header Source # 
Instance details

Defined in Hackage.Security.TUF.Header

Methods

fromJSON :: JSValue -> m Header Source #

data Root Source #

The root metadata

NOTE: We must have the invariant that ALL keys (apart from delegation keys) must be listed in rootKeys. (Delegation keys satisfy a similar invariant, see Targets.)

Instances

Instances details
HasHeader Root Source # 
Instance details

Defined in Hackage.Security.TUF.Root

VerifyRole Root Source # 
Instance details

Defined in Hackage.Security.Trusted

Monad m => ToJSON m Root Source # 
Instance details

Defined in Hackage.Security.TUF.Root

Methods

toJSON :: Root -> m JSValue Source #

MonadKeys m => FromJSON m (Signed Root) Source #

We give an instance for Signed Root rather than Root because the key environment from the root data is necessary to resolve the explicit sharing in the signatures.

Instance details

Defined in Hackage.Security.TUF.Root

Methods

fromJSON :: JSValue -> m (Signed Root) Source #

data Snapshot Source #

Constructors

Snapshot 

Fields

data Targets Source #

Target metadata

Most target files do not need expiry dates because they are not subject to change (and hence attacks like freeze attacks are not a concern).

Instances

Instances details
Show Targets Source # 
Instance details

Defined in Hackage.Security.TUF.Targets

HasHeader Targets Source # 
Instance details

Defined in Hackage.Security.TUF.Targets

MonadKeys m => FromJSON m Targets Source # 
Instance details

Defined in Hackage.Security.TUF.Targets

Monad m => ToJSON m Targets Source # 
Instance details

Defined in Hackage.Security.TUF.Targets

Methods

toJSON :: Targets -> m JSValue Source #

MonadKeys m => FromJSON m (Signed Targets) Source # 
Instance details

Defined in Hackage.Security.TUF.Targets

newtype FileLength Source #

File length

Having verified file length information means we can protect against endless data attacks and similar.

Constructors

FileLength 

Fields

newtype Hash Source #

File hash

Constructors

Hash String 

Instances

Instances details
Show Hash Source # 
Instance details

Defined in Hackage.Security.TUF.Common

Methods

showsPrec :: Int -> Hash -> ShowS #

show :: Hash -> String #

showList :: [Hash] -> ShowS #

Eq Hash Source # 
Instance details

Defined in Hackage.Security.TUF.Common

Methods

(==) :: Hash -> Hash -> Bool #

(/=) :: Hash -> Hash -> Bool #

Ord Hash Source # 
Instance details

Defined in Hackage.Security.TUF.Common

Methods

compare :: Hash -> Hash -> Ordering #

(<) :: Hash -> Hash -> Bool #

(<=) :: Hash -> Hash -> Bool #

(>) :: Hash -> Hash -> Bool #

(>=) :: Hash -> Hash -> Bool #

max :: Hash -> Hash -> Hash #

min :: Hash -> Hash -> Hash #

ReportSchemaErrors m => FromJSON m Hash Source # 
Instance details

Defined in Hackage.Security.TUF.Common

Methods

fromJSON :: JSValue -> m Hash Source #

Monad m => ToJSON m Hash Source # 
Instance details

Defined in Hackage.Security.TUF.Common

Methods

toJSON :: Hash -> m JSValue Source #

newtype KeyThreshold Source #

Key threshold

The key threshold is the minimum number of keys a document must be signed with. Key thresholds are specified in RoleSpec or DelegationsSpec.

Constructors

KeyThreshold Int54 

data HashFn Source #

Constructors

HashFnSHA256 
HashFnMD5 

Instances

Instances details
Show HashFn Source # 
Instance details

Defined in Hackage.Security.TUF.FileInfo

Eq HashFn Source # 
Instance details

Defined in Hackage.Security.TUF.FileInfo

Methods

(==) :: HashFn -> HashFn -> Bool #

(/=) :: HashFn -> HashFn -> Bool #

Ord HashFn Source # 
Instance details

Defined in Hackage.Security.TUF.FileInfo

ReportSchemaErrors m => FromObjectKey m HashFn Source # 
Instance details

Defined in Hackage.Security.TUF.FileInfo

Monad m => ToObjectKey m HashFn Source # 
Instance details

Defined in Hackage.Security.TUF.FileInfo

fileInfo :: ByteString -> FileInfo Source #

Compute FileInfo

TODO: Currently this will load the entire input bytestring into memory. We need to make this incremental, by computing the length and all hashes in a single traversal over the input.

compareTrustedFileInfo Source #

Arguments

:: FileInfo

expected (from trusted TUF files)

-> FileInfo

actual (from fileInfo on target file)

-> Bool 

Compare the expected trusted file info against the actual file info of a target file.

This should be used only when the FileInfo is already known. If we want to compare known FileInfo against a file on disk we should delay until we have confirmed that the file lengths match (see downloadedVerify).

fileInfoSHA256 :: FileInfo -> Maybe Hash Source #

Extract SHA256 hash from FileInfo (if present)

class HasHeader a where Source #

Methods

fileExpires :: Lens' a FileExpires Source #

File expiry date

fileVersion :: Lens' a FileVersion Source #

File version (monotonically increasing counter)

newtype FileVersion Source #

File version

The file version is a flat integer which must monotonically increase on every file update.

Show and Read instance are defined in terms of the underlying Int (this is used for example by Hackage during the backup process).

Constructors

FileVersion Int54 

newtype FileExpires Source #

File expiry date

A Nothing value here means no expiry. That makes it possible to set some files to never expire. (Note that not having the Maybe in the type here still allows that, because you could set an expiry date 2000 years into the future. By having the Maybe here we avoid the _need_ for such encoding issues.)

Constructors

FileExpires (Maybe UTCTime) 

data CacheLayout Source #

Location of the various files we cache

Although the generic TUF algorithms do not care how we organize the cache, we nonetheless specify this here because as long as there are tools which access files in the cache directly we need to define the cache layout. See also comments for defaultCacheLayout.

Constructors

CacheLayout 

Fields

cabalCacheLayout :: CacheLayout Source #

The cache layout cabal-install uses

We cache the index as cache/00-index.tar; this is important because `cabal-install` expects to find it there (and does not currently go through the hackage-security library to get files from the index).

data IndexLayout Source #

Layout of the files within the index tarball

Constructors

IndexLayout 

Fields

hackageIndexLayout :: IndexLayout Source #

The layout of the index as maintained on Hackage

data RepoLayout Source #

Layout of a repository

Constructors

RepoLayout 

Fields

hackageRepoLayout :: RepoLayout Source #

The layout used on Hackage

cabalLocalRepoLayout :: RepoLayout Source #

Layout used by cabal for ("legacy") local repos

Obviously, such repos do not normally contain any of the TUF files, so their location is more or less arbitrary here.

data Mirror Source #

Definition of a mirror

NOTE: Unlike the TUF specification, we require that all mirrors must have the same format. That is, we omit metapath and targetspath.

Constructors

Mirror 

Instances

Instances details
Show Mirror Source # 
Instance details

Defined in Hackage.Security.TUF.Mirrors

ReportSchemaErrors m => FromJSON m Mirror Source # 
Instance details

Defined in Hackage.Security.TUF.Mirrors

Methods

fromJSON :: JSValue -> m Mirror Source #

Monad m => ToJSON m Mirror Source # 
Instance details

Defined in Hackage.Security.TUF.Mirrors

Methods

toJSON :: Mirror -> m JSValue Source #

data MirrorContent Source #

Full versus partial mirrors

The TUF spec explicitly allows for partial mirrors, with the mirrors file specifying (through patterns) what is available from partial mirrors.

For now we only support full mirrors; if we wanted to add partial mirrors, we would add a second MirrorPartial constructor here with arguments corresponding to TUF's metacontent and targetscontent fields.

Constructors

MirrorFull 

Instances

Instances details
Show MirrorContent Source # 
Instance details

Defined in Hackage.Security.TUF.Mirrors

describeMirror :: Mirror -> MirrorDescription Source #

Give a human-readable description of a particular mirror

(for use in error messages)

data RepoRoot Source #

The root of the repository

Repository roots can be anchored at a remote URL or a local directory.

Note that even for remote repos RepoRoot is (potentially) different from Web -- for a repository located at, say, http://hackage.haskell.org they happen to coincide, but for one location at http://example.com/some/subdirectory they do not.

Instances

Instances details
Pretty (Path RepoRoot) Source # 
Instance details

Defined in Hackage.Security.TUF.Paths

type RepoPath = Path RepoRoot Source #

Paths relative to the root of the repository

data IndexRoot Source #

The root of the index tarball

Instances

Instances details
Pretty (Path IndexRoot) Source # 
Instance details

Defined in Hackage.Security.TUF.Paths

type IndexPath = Path IndexRoot Source #

Paths relative to the root of the index tarball

data CacheRoot Source #

The cache directory

Instances

Instances details
Pretty (Path CacheRoot) Source # 
Instance details

Defined in Hackage.Security.TUF.Paths

anchorCachePath :: Path root -> CachePath -> Path root Source #

Anchor a cache path to the location of the cache

data Delegation Source #

A delegation

A delegation is a pair of a pattern and a replacement.

See match for an example.

Constructors

Delegation (Pattern a) (Replacement a) 

Instances

Instances details
Show Delegation Source # 
Instance details

Defined in Hackage.Security.TUF.Patterns

Lift Delegation Source # 
Instance details

Defined in Hackage.Security.TUF.Patterns

Methods

lift :: Quote m => Delegation -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => Delegation -> Code m Delegation #

data RoleSpec a Source #

Role specification

The phantom type indicates what kind of type this role is meant to verify.

Instances

Instances details
MonadKeys m => FromJSON m (RoleSpec a) Source # 
Instance details

Defined in Hackage.Security.TUF.Root

Methods

fromJSON :: JSValue -> m (RoleSpec a) Source #

Monad m => ToJSON m (RoleSpec a) Source # 
Instance details

Defined in Hackage.Security.TUF.Root

Methods

toJSON :: RoleSpec a -> m JSValue Source #

Show (RoleSpec a) Source # 
Instance details

Defined in Hackage.Security.TUF.Root

Methods

showsPrec :: Int -> RoleSpec a -> ShowS #

show :: RoleSpec a -> String #

showList :: [RoleSpec a] -> ShowS #

newtype Signatures Source #

A list of signatures

Invariant: each signature must be made with a different key. We enforce this invariant for incoming untrusted data (fromPreSignatures) but not for lists of signatures that we create in code.

Constructors

Signatures [Signature] 

Instances

Instances details
MonadKeys m => FromJSON m Signatures Source # 
Instance details

Defined in Hackage.Security.TUF.Signed

Monad m => ToJSON m Signatures Source # 
Instance details

Defined in Hackage.Security.TUF.Signed

unsigned :: a -> Signed a Source #

Create a new document without any signatures

withSignatures :: ToJSON WriteJSON a => RepoLayout -> [Some Key] -> a -> Signed a Source #

Sign a document

withSignatures' :: ToJSON Identity a => [Some Key] -> a -> Signed a Source #

Variation on withSignatures that doesn't need the repo layout

signRendered :: [Some Key] -> ByteString -> Signatures Source #

Construct signatures for already rendered value

signedFromJSON :: (MonadKeys m, FromJSON m a) => JSValue -> m (Signed a) Source #

General FromJSON instance for signed datatypes

We don't give a general FromJSON instance for Signed because for some datatypes we need to do something special (datatypes where we need to read key environments); for instance, see the "Signed Root" instance.

verifySignatures :: JSValue -> Signatures -> Bool Source #

Signature verification

NOTES: 1. By definition, the signature must be verified against the canonical JSON format. This means we _must_ parse and then pretty print (as we do here) because the document as stored may or may not be in canonical format. 2. However, it is important that we NOT translate from the JSValue to whatever internal datatype we are using and then back to JSValue, because that may not roundtrip: we must allow for additional fields in the JSValue that we ignore (and would therefore lose when we attempt to roundtrip). 3. We verify that all signatures are valid, but we cannot verify (here) that these signatures are signed with the right key, or that we have a sufficient number of signatures. This will be the responsibility of the calling code.

data UninterpretedSignatures a Source #

File with uninterpreted signatures

Sometimes we want to be able to read a file without interpreting the signatures (that is, resolving the key IDs) or doing any kind of checks on them. One advantage of this is that this allows us to read many file types without any key environment at all, which is sometimes useful.

data PreSignature Source #

A signature with a key ID (rather than an actual key)

This corresponds precisely to the TUF representation of a signature.

Instances

Instances details
Show PreSignature Source # 
Instance details

Defined in Hackage.Security.TUF.Signed

ReportSchemaErrors m => FromJSON m PreSignature Source # 
Instance details

Defined in Hackage.Security.TUF.Signed

Monad m => ToJSON m PreSignature Source # 
Instance details

Defined in Hackage.Security.TUF.Signed

fromPreSignature :: MonadKeys m => PreSignature -> m Signature Source #

Convert a pre-signature to a signature

Verifies that the key type matches the advertised method.

fromPreSignatures :: MonadKeys m => [PreSignature] -> m Signatures Source #

Convert a list of PreSignatures to a list of Signatures

This verifies the invariant that all signatures are made with different keys. We do this on the presignatures rather than the signatures so that we can do the check on key IDs, rather than keys (the latter don't have an Ord instance).

toPreSignature :: Signature -> PreSignature Source #

Convert signature to pre-signature

toPreSignatures :: Signatures -> [PreSignature] Source #

Convert list of pre-signatures to a list of signatures

data Delegations Source #

Delegations

Much like the Root datatype, this must have an invariant that ALL used keys (apart from the global keys, which are in the root key environment) must be listed in delegationsKeys.

Instances

Instances details
Show Delegations Source # 
Instance details

Defined in Hackage.Security.TUF.Targets

MonadKeys m => FromJSON m Delegations Source # 
Instance details

Defined in Hackage.Security.TUF.Targets

Monad m => ToJSON m Delegations Source # 
Instance details

Defined in Hackage.Security.TUF.Targets

data DelegationSpec Source #

Delegation specification

NOTE: This is a close analogue of RoleSpec.

data Key a where Source #

Constructors

KeyEd25519 :: PublicKey -> SecretKey -> Key Ed25519 

Instances

Instances details
HasKeyId Key Source # 
Instance details

Defined in Hackage.Security.Key

Methods

keyId :: Key typ -> KeyId Source #

SomeEq Key Source # 
Instance details

Defined in Hackage.Security.Key

Methods

someEq :: DictEq (Key a) Source #

SomeShow Key Source # 
Instance details

Defined in Hackage.Security.Key

Methods

someShow :: DictShow (Key a) Source #

ReportSchemaErrors m => FromJSON m (Some Key) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

fromJSON :: JSValue -> m (Some Key) Source #

Monad m => ToJSON m (Key typ) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

toJSON :: Key typ -> m JSValue Source #

Monad m => ToJSON m (Some Key) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

toJSON :: Some Key -> m JSValue Source #

Show (Key typ) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

showsPrec :: Int -> Key typ -> ShowS #

show :: Key typ -> String #

showList :: [Key typ] -> ShowS #

Eq (Key typ) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

(==) :: Key typ -> Key typ -> Bool #

(/=) :: Key typ -> Key typ -> Bool #

sign :: PrivateKey typ -> ByteString -> ByteString Source #

Sign a bytestring and return the signature

TODO: It is unfortunate that we have to convert to a strict bytestring for ed25519

data PublicKey a where Source #

Constructors

PublicKeyEd25519 :: PublicKey -> PublicKey Ed25519 

Instances

Instances details
HasKeyId PublicKey Source # 
Instance details

Defined in Hackage.Security.Key

Methods

keyId :: PublicKey typ -> KeyId Source #

SomeEq PublicKey Source # 
Instance details

Defined in Hackage.Security.Key

SomeShow PublicKey Source # 
Instance details

Defined in Hackage.Security.Key

ReportSchemaErrors m => FromJSON m (Some PublicKey) Source # 
Instance details

Defined in Hackage.Security.Key

Monad m => ToJSON m (PublicKey typ) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

toJSON :: PublicKey typ -> m JSValue Source #

Monad m => ToJSON m (Some PublicKey) Source # 
Instance details

Defined in Hackage.Security.Key

Show (PublicKey typ) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

showsPrec :: Int -> PublicKey typ -> ShowS #

show :: PublicKey typ -> String #

showList :: [PublicKey typ] -> ShowS #

Eq (PublicKey typ) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

(==) :: PublicKey typ -> PublicKey typ -> Bool #

(/=) :: PublicKey typ -> PublicKey typ -> Bool #

data PrivateKey a where Source #

Constructors

PrivateKeyEd25519 :: SecretKey -> PrivateKey Ed25519 

Instances

Instances details
SomeEq PrivateKey Source # 
Instance details

Defined in Hackage.Security.Key

SomeShow PrivateKey Source # 
Instance details

Defined in Hackage.Security.Key

Show (PrivateKey typ) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

showsPrec :: Int -> PrivateKey typ -> ShowS #

show :: PrivateKey typ -> String #

showList :: [PrivateKey typ] -> ShowS #

Eq (PrivateKey typ) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

(==) :: PrivateKey typ -> PrivateKey typ -> Bool #

(/=) :: PrivateKey typ -> PrivateKey typ -> Bool #

data KeyType typ where Source #

Constructors

KeyTypeEd25519 :: KeyType Ed25519 

Instances

Instances details
SomeEq KeyType Source # 
Instance details

Defined in Hackage.Security.Key

Methods

someEq :: DictEq (KeyType a) Source #

SomeShow KeyType Source # 
Instance details

Defined in Hackage.Security.Key

ReportSchemaErrors m => FromJSON m (Some KeyType) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

fromJSON :: JSValue -> m (Some KeyType) Source #

Monad m => ToJSON m (KeyType typ) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

toJSON :: KeyType typ -> m JSValue Source #

Monad m => ToJSON m (Some KeyType) Source # 
Instance details

Defined in Hackage.Security.Key

Show (KeyType typ) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

showsPrec :: Int -> KeyType typ -> ShowS #

show :: KeyType typ -> String #

showList :: [KeyType typ] -> ShowS #

Eq (KeyType typ) Source # 
Instance details

Defined in Hackage.Security.Key

Methods

(==) :: KeyType typ -> KeyType typ -> Bool #

(/=) :: KeyType typ -> KeyType typ -> Bool #

someKeyId :: forall (key :: Type -> Type). HasKeyId key => Some key -> KeyId Source #

createKey :: KeyType key -> IO (Key key) Source #

newtype KeyId Source #

The key ID of a key, by definition, is the hexdigest of the SHA-256 hash of the canonical JSON form of the key where the private object key is excluded.

NOTE: The FromJSON and ToJSON instances for KeyId are intentionally omitted. Use writeKeyAsId instead.

Constructors

KeyId 

Fields

Instances

Instances details
Show KeyId Source # 
Instance details

Defined in Hackage.Security.Key

Methods

showsPrec :: Int -> KeyId -> ShowS #

show :: KeyId -> String #

showList :: [KeyId] -> ShowS #

Eq KeyId Source # 
Instance details

Defined in Hackage.Security.Key

Methods

(==) :: KeyId -> KeyId -> Bool #

(/=) :: KeyId -> KeyId -> Bool #

Ord KeyId Source # 
Instance details

Defined in Hackage.Security.Key

Methods

compare :: KeyId -> KeyId -> Ordering #

(<) :: KeyId -> KeyId -> Bool #

(<=) :: KeyId -> KeyId -> Bool #

(>) :: KeyId -> KeyId -> Bool #

(>=) :: KeyId -> KeyId -> Bool #

max :: KeyId -> KeyId -> KeyId #

min :: KeyId -> KeyId -> KeyId #

Monad m => FromObjectKey m KeyId Source # 
Instance details

Defined in Hackage.Security.Key

Monad m => ToObjectKey m KeyId Source # 
Instance details

Defined in Hackage.Security.Key

class HasKeyId (key :: Type -> Type) where Source #

Compute the key ID of a key

Methods

keyId :: key typ -> KeyId Source #

Instances

Instances details
HasKeyId Key Source # 
Instance details

Defined in Hackage.Security.Key

Methods

keyId :: Key typ -> KeyId Source #

HasKeyId PublicKey Source # 
Instance details

Defined in Hackage.Security.Key

Methods

keyId :: PublicKey typ -> KeyId Source #

We only a few bits from .Repository

data Repository (down :: Type -> Type) Source #

Repository

This is an abstract representation of a repository. It simply provides a way to download metafiles and target files, without specifying how this is done. For instance, for a local repository this could just be doing a file read, whereas for remote repositories this could be using any kind of HTTP client.

Instances

Instances details
Show (Repository down) Source # 
Instance details

Defined in Hackage.Security.Client.Repository

Methods

showsPrec :: Int -> Repository down -> ShowS #

show :: Repository down -> String #

showList :: [Repository down] -> ShowS #

class DownloadedFile (down :: Type -> Type) where Source #

Methods

downloadedVerify :: down a -> Trusted FileInfo -> IO Bool Source #

Verify a download file

downloadedRead :: down Metadata -> IO ByteString Source #

Read the file we just downloaded into memory

We never read binary data, only metadata.

downloadedCopyTo :: down a -> Path Absolute -> IO () Source #

Copy a downloaded file to its destination

data SomeRemoteError where Source #

Repository-specific exceptions

For instance, for repositories using HTTP this might correspond to a 404; for local repositories this might correspond to file-not-found, etc.

Constructors

SomeRemoteError :: forall e. Exception e => e -> SomeRemoteError 

data LogMessage Source #

Log messages

We use a RemoteFile rather than a RepoPath here because we might not have a RepoPath for the file that we were trying to download (that is, for example if the server does not provide an uncompressed tarball, it doesn't make much sense to list the path to that non-existing uncompressed tarball).

Constructors

LogRootUpdated

Root information was updated

This message is issued when the root information is updated as part of the normal check for updates procedure. If the root information is updated because of a verification error WarningVerificationError is issued instead.

LogVerificationError VerificationError

A verification error

Verification errors can be temporary, and may be resolved later; hence these are just warnings. (Verification errors that cannot be resolved are thrown as exceptions.)

LogDownloading (RemoteFile fs typ)

Download a file from a repository

LogUpdating (RemoteFile fs Binary)

Incrementally updating a file from a repository

LogSelectedMirror MirrorDescription

Selected a particular mirror

LogCannotUpdate (RemoteFile fs Binary) UpdateFailure

Updating a file failed (we will instead download it whole)

LogMirrorFailed MirrorDescription SomeException

We got an exception with a particular mirror (we will try with a different mirror if any are available)

LogLockWait (Path Absolute)

This log event is triggered before invoking a filesystem lock operation that may block for a significant amount of time; once the possibly blocking call completes successfully, LogLockWaitDone will be emitted.

Since: 0.6.0

LogLockWaitDone (Path Absolute)

Denotes completion of the operation that advertised a LogLockWait event

Since: 0.6.0

LogUnlock (Path Absolute)

Denotes the filesystem lock previously acquired (signaled by LogLockWait) has been released.

Since: 0.6.0

Instances

Instances details
Pretty LogMessage Source # 
Instance details

Defined in Hackage.Security.Client.Repository

Exceptions

uncheckClientErrors :: ((Throws VerificationError, Throws SomeRemoteError, Throws InvalidPackageException) => IO a) -> IO a Source #

Re-throw all exceptions thrown by the client API as unchecked exceptions

data VerificationError Source #

Errors thrown during role validation

Constructors

VerificationErrorSignatures TargetPath Integer [KeyId] [KeyId]

Not enough signatures signed with the appropriate keys

VerificationErrorExpired TargetPath

The file is expired

VerificationErrorVersion TargetPath

The file version is less than the previous version

VerificationErrorFileInfo TargetPath

File information mismatch

VerificationErrorUnknownTarget TargetPath

We tried to lookup file information about a particular target file, but the information wasn't in the corresponding targets.json file.

VerificationErrorMissingSHA256 TargetPath

The metadata for the specified target is missing a SHA256

VerificationErrorDeserialization TargetPath DeserializationError

Some verification errors materialize as deserialization errors

For example: if we try to deserialize a timestamp file but the timestamp key has been rolled over, deserialization of the file will fail with DeserializationErrorUnknownKey.

VerificationErrorLoop VerificationHistory

The spec stipulates that if a verification error occurs during the check for updates, we must download new root information and start over. However, we limit how often we attempt this.

We record all verification errors that occurred before we gave up.

data RootUpdated Source #

Root metadata updated (as part of the normal update process)

Constructors

RootUpdated