RemoteStreamService
extends NCSignature
in package
Uses
TDeserialize, TNCLocalSignatory, TStringTools, TNCWellKnown
Class RemoteStreamService
Table of Contents
- DATE_HEADER = 'D, d M Y H:i:s T'
- DATE_OBJECT = 'Y-m-d\\TH:i:s\\Z'
- DATE_TTL = 300
- UPDATE_DATA = 'data'
- UPDATE_HREF = 'href'
- UPDATE_INSTANCE = 'instance'
- UPDATE_ITEM = 'item'
- UPDATE_TYPE = 'type'
- $SIGNATORIES_APP : mixed
- $WEBFINGER : mixed
- $configService : ConfigService
- $dateHeader : mixed
- $interfaceService : InterfaceService
- $remoteRequest : RemoteRequest
- $ttl : int
- $urlGenerator : IURLGenerator
- __construct() : mixed
- RemoteStreamService constructor.
- addRemoteInstance() : void
- Add a remote instance, based on the address
- confirmValidRemote() : void
- TODO: confirm if method is really needed
- createSimpleSignatory() : void
- deserialize() : IDeserializable
- deserializeArray() : array<string|int, IDeserializable>
- deserializeJson() : IDeserializable
- deserializeList() : array<string|int, IDeserializable>
- downloadSignatory() : void
- extractLink() : NCWellKnownLink
- fillSimpleSignatory() : void
- generateKeys() : mixed
- generateRandomSentence() : string
- generateRandomWord() : string
- getAppSignatory() : RemoteInstance
- Returns the Signatory model for the Circles app.
- getCachedRemoteInstance() : RemoteInstance
- get RemoteInstance with confirmed and known identity from database.
- getDateDiff() : string
- getKeyOrigin() : string
- getLink() : NCWellKnownLink
- getOpenSSLAlgo() : int
- getRemoteInstanceFromAddress() : RemoteInstance
- getResourceData() : SimpleDataStore
- getWebfinger() : NCWebfinger
- humanReadable() : string
- incomingSignedRequest() : NCSignedRequest
- isFromSameInstance() : bool
- removeSimpleSignatory() : void
- resetAppSignatory() : void
- Reset the Signatory (and the Identity) for the Circles app.
- resultRequestRemoteInstance() : array<string|int, mixed>
- shortcut to requestRemoteInstance that return result if available, or exception.
- retrieveRemoteInstance() : RemoteInstance
- Add a remote instance, based on the address
- retrieveSignatory() : RemoteInstance
- retrieve Signatory.
- serialize() : array<string|int, mixed>
- serializeArray() : array<string|int, mixed>
- signOutgoingRequest() : NCSignedRequest
- signString() : string
- update() : void
- TODO: check if this method is not useless
- updateSignatory() : void
- verifyString() : mixed
- commonPart() : string
- cut() : string
- feedStringWithParams() : string
- isUuid() : bool
- token() : string
- uuid() : string
- Generate uuid: 2b5a7a87-8db1-445f-a17b-405790f91c80
- confirmAuth() : void
- Confirm the Auth of a RemoteInstance, based on the result from a request
- confirmFederatedItemExceptionFromClass() : void
- getChosenEncryption() : string
- getFederatedItemExceptionFromResult() : FederatedItemException
- getFederatedItemExceptionFromStatus() : string
- getRemoteInstanceEntry() : string
- get the value of an entry from the Signatory of the RemoteInstance.
- getUsedEncryption() : string
- parseIncomingSignatureHeader() : void
- requestRemoteInstance() : NCSignedRequest
- Send a request to a remote instance, based on: - instance: address as saved in database, - item: the item to request (incoming, event, ...) - type: GET, POST - data: Serializable to be send if needed
- setIncomingClearSignature() : void
- setIncomingSignatureHeader() : void
- setOutgoingClearSignature() : void
- setOutgoingSignatureHeader() : void
- setOutgoingSignedSignature() : void
- signingOutgoingRequest() : void
- verifyIncomingRequestContent() : void
- verifyIncomingRequestSignature() : mixed
- verifyIncomingRequestTime() : void
- verifySignedRequest() : mixed
Constants
DATE_HEADER
public
mixed
DATE_HEADER
= 'D, d M Y H:i:s T'
DATE_OBJECT
public
mixed
DATE_OBJECT
= 'Y-m-d\\TH:i:s\\Z'
DATE_TTL
public
mixed
DATE_TTL
= 300
UPDATE_DATA
public
mixed
UPDATE_DATA
= 'data'
UPDATE_HREF
public
mixed
UPDATE_HREF
= 'href'
UPDATE_INSTANCE
public
mixed
UPDATE_INSTANCE
= 'instance'
UPDATE_ITEM
public
mixed
UPDATE_ITEM
= 'item'
UPDATE_TYPE
public
mixed
UPDATE_TYPE
= 'type'
Properties
$SIGNATORIES_APP
public
static mixed
$SIGNATORIES_APP
= 'signatories'
$WEBFINGER
public
static mixed
$WEBFINGER
= '/.well-known/webfinger'
$configService
private
ConfigService
$configService
$dateHeader
private
mixed
$dateHeader
= self::DATE_HEADER
$interfaceService
private
InterfaceService
$interfaceService
$remoteRequest
private
RemoteRequest
$remoteRequest
$ttl
private
int
$ttl
= self::DATE_TTL
$urlGenerator
private
IURLGenerator
$urlGenerator
Methods
__construct()
RemoteStreamService constructor.
public
__construct(IURLGenerator $urlGenerator, RemoteRequest $remoteRequest, InterfaceService $interfaceService, ConfigService $configService) : mixed
Parameters
- $urlGenerator : IURLGenerator
- $remoteRequest : RemoteRequest
- $interfaceService : InterfaceService
- $configService : ConfigService
Return values
mixed —addRemoteInstance()
Add a remote instance, based on the address
public
addRemoteInstance(string $instance[, string $type = RemoteInstance::TYPE_EXTERNAL ][, int $iface = InterfaceService::IFACE_FRONTAL ][, bool $overwrite = false ]) : void
Parameters
- $instance : string
- $type : string = RemoteInstance::TYPE_EXTERNAL
- $iface : int = InterfaceService::IFACE_FRONTAL
- $overwrite : bool = false
Tags
Return values
void —confirmValidRemote()
TODO: confirm if method is really needed
public
confirmValidRemote(RemoteInstance $remote[, RemoteInstance|null &$stored = null ]) : void
Parameters
- $remote : RemoteInstance
- $stored : RemoteInstance|null = null
Tags
Return values
void —createSimpleSignatory()
public
createSimpleSignatory(NCSignatory $signatory) : void
Parameters
- $signatory : NCSignatory
Return values
void —deserialize()
public
deserialize(array<string|int, mixed> $data, string $class) : IDeserializable
Parameters
- $data : array<string|int, mixed>
- $class : string
Tags
Return values
IDeserializable —deserializeArray()
public
deserializeArray(array<string|int, mixed> $data, string $class[, bool $associative = false ]) : array<string|int, IDeserializable>
Parameters
- $data : array<string|int, mixed>
- $class : string
- $associative : bool = false
Return values
array<string|int, IDeserializable> —deserializeJson()
public
deserializeJson(string $json, string $class) : IDeserializable
Parameters
- $json : string
- $class : string
Tags
Return values
IDeserializable —deserializeList()
public
deserializeList(string $json, string $class) : array<string|int, IDeserializable>
Parameters
- $json : string
- $class : string
Tags
Return values
array<string|int, IDeserializable> —downloadSignatory()
public
downloadSignatory(NCSignatory $signatory[, string $keyId = '' ][, array<string|int, mixed> $params = [] ][, NCRequest|null $request = null ]) : void
Parameters
- $signatory : NCSignatory
- $keyId : string = ''
- $params : array<string|int, mixed> = []
- $request : NCRequest|null = null
Tags
Return values
void —extractLink()
public
extractLink(string $rel, NCWebfinger $webfinger) : NCWellKnownLink
Parameters
- $rel : string
- $webfinger : NCWebfinger
Tags
Return values
NCWellKnownLink —fillSimpleSignatory()
public
fillSimpleSignatory(NCSignatory $signatory[, bool $generate = false ]) : void
Parameters
- $signatory : NCSignatory
- $generate : bool = false
Tags
Return values
void —generateKeys()
public
generateKeys(NCSignatory $signatory[, string $digest = 'rsa' ][, int $bits = 2048 ][, int $type = OPENSSL_KEYTYPE_RSA ]) : mixed
Parameters
- $signatory : NCSignatory
- $digest : string = 'rsa'
- $bits : int = 2048
- $type : int = OPENSSL_KEYTYPE_RSA
Return values
mixed —generateRandomSentence()
public
generateRandomSentence([int $words = 5 ]) : string
Parameters
- $words : int = 5
Return values
string —generateRandomWord()
public
generateRandomWord([int $length = 8 ]) : string
Parameters
- $length : int = 8
Return values
string —getAppSignatory()
Returns the Signatory model for the Circles app.
public
getAppSignatory([bool $generate = true ][, string $confirmKey = '' ]) : RemoteInstance
Can be signed with a confirmKey.
Parameters
- $generate : bool = true
- $confirmKey : string = ''
Tags
Return values
RemoteInstance —getCachedRemoteInstance()
get RemoteInstance with confirmed and known identity from database.
public
getCachedRemoteInstance(string $instance) : RemoteInstance
Parameters
- $instance : string
Tags
Return values
RemoteInstance —getDateDiff()
public
getDateDiff(int $first, int $second[, bool $short = false ][, array<string|int, mixed> $words = [] ]) : string
Parameters
- $first : int
- $second : int
- $short : bool = false
- $words : array<string|int, mixed> = []
Tags
Return values
string —getKeyOrigin()
public
getKeyOrigin(string $keyId) : string
Parameters
- $keyId : string
Tags
Return values
string —getLink()
public
getLink(string $host, string $subject, string $rel) : NCWellKnownLink
Parameters
- $host : string
- $subject : string
- $rel : string
Tags
Return values
NCWellKnownLink —getOpenSSLAlgo()
public
getOpenSSLAlgo(NCSignatory $signatory) : int
Parameters
- $signatory : NCSignatory
Return values
int —getRemoteInstanceFromAddress()
public
getRemoteInstanceFromAddress(string $address) : RemoteInstance
Parameters
- $address : string
Tags
Return values
RemoteInstance —getResourceData()
public
getResourceData(string $host, string $subject, string $rel) : SimpleDataStore
Parameters
- $host : string
- $subject : string
- $rel : string
Tags
Return values
SimpleDataStore —getWebfinger()
public
getWebfinger(string $host, string $subject[, string $rel = '' ]) : NCWebfinger
Parameters
- $host : string
- $subject : string
- $rel : string = ''
Tags
Return values
NCWebfinger —humanReadable()
public
humanReadable(int $bytes) : string
Parameters
- $bytes : int
Return values
string —incomingSignedRequest()
public
incomingSignedRequest([string $body = '' ]) : NCSignedRequest
Parameters
- $body : string = ''
Tags
Return values
NCSignedRequest —isFromSameInstance()
public
isFromSameInstance(string $instance, string $check) : bool
Parameters
- $instance : string
- $check : string
Tags
Return values
bool —removeSimpleSignatory()
public
removeSimpleSignatory(NCSignatory $signatory) : void
Parameters
- $signatory : NCSignatory
Return values
void —resetAppSignatory()
Reset the Signatory (and the Identity) for the Circles app.
public
resetAppSignatory() : void
Return values
void —resultRequestRemoteInstance()
shortcut to requestRemoteInstance that return result if available, or exception.
public
resultRequestRemoteInstance(string $instance, string $item[, int $type = Request::TYPE_GET ][, JsonSerializable|null $object = null ][, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>
Parameters
- $instance : string
- $item : string
- $type : int = Request::TYPE_GET
- $object : JsonSerializable|null = null
- $params : array<string|int, mixed> = []
Tags
Return values
array<string|int, mixed> —retrieveRemoteInstance()
Add a remote instance, based on the address
public
retrieveRemoteInstance(string $instance) : RemoteInstance
Parameters
- $instance : string
Tags
Return values
RemoteInstance —retrieveSignatory()
retrieve Signatory.
public
retrieveSignatory(string $keyId[, bool $refresh = true ]) : RemoteInstance
Parameters
- $keyId : string
- $refresh : bool = true
Tags
Return values
RemoteInstance —serialize()
public
serialize(JsonSerializable $model) : array<string|int, mixed>
Parameters
- $model : JsonSerializable
Return values
array<string|int, mixed> —serializeArray()
public
serializeArray(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
- $data : array<string|int, mixed>
Return values
array<string|int, mixed> —signOutgoingRequest()
public
signOutgoingRequest(NCRequest $request, NCSignatory $signatory) : NCSignedRequest
Parameters
- $request : NCRequest
- $signatory : NCSignatory
Tags
Return values
NCSignedRequest —signString()
public
signString(string $clear, NCSignatory $signatory) : string
Parameters
- $clear : string
- $signatory : NCSignatory
Tags
Return values
string —update()
TODO: check if this method is not useless
public
update(RemoteInstance $remote[, string $update = self::UPDATE_DATA ]) : void
Parameters
- $remote : RemoteInstance
- $update : string = self::UPDATE_DATA
Tags
Return values
void —updateSignatory()
public
updateSignatory(NCSignatory $signatory, array<string|int, mixed> $json[, string $keyId = '' ]) : void
Parameters
- $signatory : NCSignatory
- $json : array<string|int, mixed>
- $keyId : string = ''
Tags
Return values
void —verifyString()
public
verifyString(string $clear, string $signed, string $publicKey[, string $algo = NCSignatory::SHA256 ]) : mixed
Parameters
- $clear : string
- $signed : string
- $publicKey : string
- $algo : string = NCSignatory::SHA256
Tags
Return values
mixed —commonPart()
protected
commonPart(string $str1, string $str2[, bool $cs = true ]) : string
Parameters
- $str1 : string
- $str2 : string
- $cs : bool = true
-
case sensitive ?
Return values
string —cut()
protected
cut(string $line, int $length) : string
Parameters
- $line : string
- $length : int
Return values
string —feedStringWithParams()
protected
feedStringWithParams(string $line, array<string|int, mixed> $params) : string
Parameters
- $line : string
- $params : array<string|int, mixed>
Return values
string —isUuid()
protected
isUuid(string $uuid) : bool
Parameters
- $uuid : string
Return values
bool —token()
protected
token([int $length = 15 ]) : string
Parameters
- $length : int = 15
Return values
string —uuid()
Generate uuid: 2b5a7a87-8db1-445f-a17b-405790f91c80
protected
uuid(int $length) : string
Parameters
- $length : int
Return values
string —confirmAuth()
Confirm the Auth of a RemoteInstance, based on the result from a request
private
confirmAuth(RemoteInstance $remote, string $auth) : void
Parameters
- $remote : RemoteInstance
- $auth : string
Tags
Return values
void —confirmFederatedItemExceptionFromClass()
private
confirmFederatedItemExceptionFromClass(ReflectionClass $class) : void
Parameters
- $class : ReflectionClass
Tags
Return values
void —getChosenEncryption()
private
getChosenEncryption(NCSignatory $signatory) : string
Parameters
- $signatory : NCSignatory
Return values
string —getFederatedItemExceptionFromResult()
private
getFederatedItemExceptionFromResult(NCRequestResult $result) : FederatedItemException
Parameters
- $result : NCRequestResult
Return values
FederatedItemException —getFederatedItemExceptionFromStatus()
private
getFederatedItemExceptionFromStatus(int $statusCode) : string
Parameters
- $statusCode : int
Return values
string —getRemoteInstanceEntry()
get the value of an entry from the Signatory of the RemoteInstance.
private
getRemoteInstanceEntry(string $instance, string $item[, array<string|int, mixed> $params = [] ]) : string
Parameters
- $instance : string
- $item : string
- $params : array<string|int, mixed> = []
Tags
Return values
string —getUsedEncryption()
private
getUsedEncryption(NCSignedRequest $signedRequest) : string
Parameters
- $signedRequest : NCSignedRequest
Return values
string —parseIncomingSignatureHeader()
private
parseIncomingSignatureHeader(NCSignedRequest $signedRequest) : void
Parameters
- $signedRequest : NCSignedRequest
Tags
Return values
void —requestRemoteInstance()
Send a request to a remote instance, based on: - instance: address as saved in database, - item: the item to request (incoming, event, ...) - type: GET, POST - data: Serializable to be send if needed
private
requestRemoteInstance(string $instance, string $item[, int $type = Request::TYPE_GET ][, JsonSerializable|null $object = null ][, array<string|int, mixed> $params = [] ]) : NCSignedRequest
Parameters
- $instance : string
- $item : string
- $type : int = Request::TYPE_GET
- $object : JsonSerializable|null = null
- $params : array<string|int, mixed> = []
Tags
Return values
NCSignedRequest —setIncomingClearSignature()
private
setIncomingClearSignature(NCSignedRequest $signedRequest) : void
Parameters
- $signedRequest : NCSignedRequest
Tags
Return values
void —setIncomingSignatureHeader()
private
setIncomingSignatureHeader(NCSignedRequest $signedRequest) : void
Parameters
- $signedRequest : NCSignedRequest
Return values
void —setOutgoingClearSignature()
private
setOutgoingClearSignature(NCSignedRequest $signedRequest) : void
Parameters
- $signedRequest : NCSignedRequest
Return values
void —setOutgoingSignatureHeader()
private
setOutgoingSignatureHeader(NCSignedRequest $signedRequest) : void
Parameters
- $signedRequest : NCSignedRequest
Return values
void —setOutgoingSignedSignature()
private
setOutgoingSignedSignature(NCSignedRequest $signedRequest) : void
Parameters
- $signedRequest : NCSignedRequest
Tags
Return values
void —signingOutgoingRequest()
private
signingOutgoingRequest(NCSignedRequest $signedRequest) : void
Parameters
- $signedRequest : NCSignedRequest
Return values
void —verifyIncomingRequestContent()
private
verifyIncomingRequestContent(NCSignedRequest $signedRequest) : void
Parameters
- $signedRequest : NCSignedRequest
Tags
Return values
void —verifyIncomingRequestSignature()
private
verifyIncomingRequestSignature(NCSignedRequest $signedRequest) : mixed
Parameters
- $signedRequest : NCSignedRequest
Tags
Return values
mixed —verifyIncomingRequestTime()
private
verifyIncomingRequestTime(NCSignedRequest $signedRequest) : void
Parameters
- $signedRequest : NCSignedRequest
Tags
Return values
void —verifySignedRequest()
private
verifySignedRequest(NCSignedRequest $signedRequest) : mixed
Parameters
- $signedRequest : NCSignedRequest