{"id":13995142,"url":"https://github.com/trilemma-dev/SecureXPC","last_synced_at":"2025-07-22T21:32:05.009Z","repository":{"id":40364247,"uuid":"415001618","full_name":"trilemma-dev/SecureXPC","owner":"trilemma-dev","description":"A simple and secure XPC framework for Swift","archived":false,"fork":false,"pushed_at":"2023-06-27T13:11:29.000Z","size":578,"stargazers_count":78,"open_issues_count":5,"forks_count":15,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-11-17T17:38:13.897Z","etag":null,"topics":["machservices","macos","smjobbless","swift","xpc"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trilemma-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-08T13:40:16.000Z","updated_at":"2024-11-05T01:05:26.000Z","dependencies_parsed_at":"2022-07-12T13:33:44.919Z","dependency_job_id":null,"html_url":"https://github.com/trilemma-dev/SecureXPC","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trilemma-dev%2FSecureXPC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trilemma-dev%2FSecureXPC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trilemma-dev%2FSecureXPC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trilemma-dev%2FSecureXPC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trilemma-dev","download_url":"https://codeload.github.com/trilemma-dev/SecureXPC/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227177790,"owners_count":17743167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["machservices","macos","smjobbless","swift","xpc"],"created_at":"2024-08-09T14:03:16.128Z","updated_at":"2024-11-29T17:31:06.629Z","avatar_url":"https://github.com/trilemma-dev.png","language":"Swift","readme":"Use pure Swift to easily and securely communicate with XPC services and Mach services. A client-server model enables you\nto use your own [`Codable`](https://developer.apple.com/documentation/swift/codable) conforming types to send requests\nto routes you define and receive responses. \n\nSecureXPC uses [Swift concurrency](https://docs.swift.org/swift-book/LanguageGuide/Concurrency.html) on macOS 10.15 and\nlater allowing clients to make non-blocking asynchronous requests to servers. A closure-based API is also available\nproviding compatibility back to OS X 10.10.\n\nThis package can be used to communicate with any type of XPC service or Mach service, with customized support for:\n- [XPC services](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingXPCServices.html)\n- Helper tools installed using \n  [`SMJobBless`](https://developer.apple.com/documentation/servicemanagement/1431078-smjobbless)\n- Login items enabled with \n  [`SMLoginItemSetEnabled`](https://developer.apple.com/documentation/servicemanagement/1501557-smloginitemsetenabled)\n- Daemons registered via \n  [`SMAppService.daemon(plistName:)`](https://developer.apple.com/documentation/servicemanagement/smappservice/3945410-daemon)\n- Agents registered via \n  [`SMAppService.agent(plistName:)`](https://developer.apple.com/documentation/servicemanagement/smappservice/3945409-agent)\n\nIt's built with security in mind, minimizing the opportunities for \n[exploits](https://objectivebythesea.com/v3/talks/OBTS_v3_wReguła.pdf). Security checks are performed against the actual\ncalling process instead of relying on PIDs which are known to be\n[insecure](https://saelo.github.io/presentations/warcon18_dont_trust_the_pid.pdf).\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ftrilemma-dev%2FSecureXPC%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/trilemma-dev/SecureXPC)\n\n# Usage\nThe envisioned pattern when using this package is to define routes in a shared file, create a server in one program\n(such as a helper tool) and register these routes, then from another program (such as an app) create a client and send\nrequests to these routes.\n\n## Routes\nIn a file shared by the client and server define one or more routes:\n```swift\nlet route = XPCRoute.named(\"bedazzle\")\n                    .withMessageType(String.self)\n                    .withReplyType(Bool.self)\n```\n\n## Server\nIn one program retrieve a server, register those routes, and then start the server:\n```swift\n    ...\n    let server = \u003c# server retrieval here #\u003e\n    server.registerRoute(route, handler: bedazzle)\n    server.startAndBlock()\n}\n\nprivate func bedazzle(message: String) throws -\u003e Bool {\n     \u003c# implementation here #\u003e\n}\n```\n\nOn macOS 10.15 and later `async` functions and closures can also be registered as the handler for a route.\n\nThere are multiple types of servers which can be retrieved:\n - `XPCServer.forThisXPCService()`\n     - For an XPC service, which is a private helper tool available only to the main application that contains it\n - `XPCServer.forMachService()`\n     - For agents and daemons registered with `SMAppService`, `SMJobBless` helper tools, and `SMLoginItemSetEnabled`\n       login items\n - `XPCServer.forMachService(withCriteria:)`\n     - For any type of Mach service including \"classic\" agents and daemons; see documentation for details\n - `XPCServer.makeAnonymous()`\n     - Typically used for testing purposes\n - `XPCServer.makeAnonymous(withClientRequirements:)`\n     - Enables advanced scenarios including apps directly communicating with each other; see documentation for details\n\n## Client\nIn another program retrieve a client, then send a request to a registered route:\n```swift\nlet client = \u003c# client retrieval here #\u003e\nlet reply = try await client.sendMessage(\"Get Schwifty\", to: route)\n```\n\nClosure-based variants are available for macOS 10.14 and earlier:\n```swift\nlet client = \u003c# client retrieval here #\u003e\nclient.sendMessage(\"Get Schwifty\", to: route, withResponse: { result in\n    switch result {\n        case .success(let reply):\n            \u003c# use the reply #\u003e\n        case .failure(let error):\n            \u003c# handle the error #\u003e\n    }\n})\n```\n\nThere are three types of clients which can be retrieved:\n - `XPCClient.forXPCService(named:)`\n     - For communicating with an XPC service\n     - This corresponds to servers created with `XPCServer.forThisXPCService()`\n - `XPCClient.forMachService(named:withServerRequirement:)`\n     - For communicating with a Mach service\n     - This corresponds to servers created with `XPCServer.forMachService()` or\n       `XPCServer.forMachService(withCriteria:)`\n - `XPCClient.forEndpoint(_:withServerRequirement:)`\n    - This is the only way to communicate with an anonymous server\n    - This corresponds to servers created with `XPCServer.makeAnonymous()` or\n      `XPCServer.makeAnonymous(withClientRequirements:)`\n    - This type of client can also be used to communicate with any server via its `endpoint` property\n\n---\n\n# Questions you may have\nSee the [FAQ](FAQ.md) for answers to questions you may have or didn't even realize you wanted answered including topics\nsuch as using live file handles, sharing memory between processes, and working within sandbox restrictions.\n","funding_links":[],"categories":["Swift"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrilemma-dev%2FSecureXPC","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrilemma-dev%2FSecureXPC","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrilemma-dev%2FSecureXPC/lists"}