ถอดรหัสนโยบาย JWS

คุณกำลังดูเอกสารประกอบ Apigee Edge
ไปที่ เอกสารประกอบเกี่ยวกับ Apigee X.
ข้อมูล

อะไร

ถอดรหัสส่วนหัว JWS โดยไม่ยืนยันลายเซ็นใน JWS และเขียนส่วนหัวแต่ละรายการไปยัง ของตัวแปรโฟลว์ นโยบายนี้จะมีประโยชน์มากที่สุดเมื่อใช้ร่วมกับนโยบาย VerifyJWS เมื่อต้องทราบค่าของส่วนหัวจากภายใน JWS ก่อนยืนยันลายเซ็นของ JWS

JWS อาจมีเพย์โหลดที่แนบมาตามในแบบฟอร์ม

header.payload.signature

หรือ JWS สามารถละเว้นเพย์โหลดที่เรียกว่าเพย์โหลดที่ถอดออกได้ และอยู่ในรูปแบบดังนี้

header..signature

นโยบาย DecodeJWS ใช้งานได้กับทั้ง 2 ฟอร์มเนื่องจากจะถอดรหัสเฉพาะส่วนส่วนหัวของ JWS นอกจากนี้ นโยบาย DecodeJWS ยังสามารถใช้ได้ด้วยเช่นกันโดยไม่คำนึงถึงอัลกอริทึมที่ใช้ในการลงนาม JWS

ดูรายละเอียดข้อมูลเบื้องต้นได้ที่ภาพรวมนโยบายของ JWS และ JWT และภาพรวมของรูปแบบของ JWS

วิดีโอ

ดูวิดีโอสั้นๆ เพื่อดูวิธีถอดรหัส JWT ขณะที่วิดีโอนี้ ของ JWT โดยเฉพาะ แนวคิดหลายๆ อย่างของ JWS จะเหมือนกัน

ตัวอย่าง: ถอดรหัส JWS

นโยบายที่แสดงด้านล่างจะถอดรหัส JWS ที่พบในตัวแปรโฟลว์ var.JWS ช่วงเวลานี้ จะต้องแสดงตัวแปรและมี JWS ที่ทำงานได้ (ถอดรหัสได้) นโยบายสามารถรับ JWS ได้จาก ตัวแปรใดก็ตามของโฟลว์ได้

<DecodeJWS name="JWS-Decode-HS256">
    <DisplayName>JWS Verify HS256</DisplayName>
    <Source>var.JWS</Source>
</DecodeJWS>

สำหรับส่วนหัวแต่ละรายการในส่วนหัวของ JWS นโยบายจะตั้งค่าตัวแปรโฟลว์ที่ชื่อว่า

jws.policy-name.header.header-name

หาก JWS มีเพย์โหลดแนบอยู่ ระบบจะตั้งค่า jws.policy-name.header.payload โฟลว์ตัวแปรไปยังเพย์โหลด สำหรับเพย์โหลดที่ปลดออกแล้ว payload จะว่างเปล่า ดูตัวแปรโฟลว์สำหรับรายการตัวแปรทั้งหมดที่นโยบายนี้กำหนดไว้

การอ้างอิงองค์ประกอบสำหรับการถอดรหัส JWS

การอ้างอิงนโยบายอธิบายองค์ประกอบและแอตทริบิวต์ของนโยบาย Decode JWS

แอตทริบิวต์ที่ ใช้กับองค์ประกอบระดับบนสุด

<DecodeJWS name="JWS" continueOnError="false" enabled="true" async="false">

แอตทริบิวต์ต่อไปนี้มีอยู่ในองค์ประกอบระดับบนสุดของนโยบายทั้งหมด

แอตทริบิวต์ คำอธิบาย ค่าเริ่มต้น การตรวจหาบุคคล
ชื่อ ชื่อภายในของนโยบาย อักขระที่คุณสามารถใช้ในชื่อจะถูกจำกัดไว้เฉพาะ: A-Z0-9._\-$ % อย่างไรก็ตาม UI การจัดการ Edge จะบังคับใช้เพิ่มเติม เช่น การนำอักขระที่ไม่ใช่ตัวอักษรและตัวเลขคละกันออกโดยอัตโนมัติ

(ไม่บังคับ) ใช้องค์ประกอบ <displayname></displayname> เพื่อ ติดป้ายกำกับนโยบายในเครื่องมือแก้ไขพร็อกซีของ UI การจัดการด้วยภาษาอื่นที่เป็นภาษาธรรมชาติ ชื่อ

ไม่มี ต้องระบุ
continueOnError ตั้งค่าเป็น false เพื่อแสดงผลข้อผิดพลาดเมื่อนโยบายล้มเหลว เป็นเรื่องปกติ พฤติกรรมสำหรับนโยบายส่วนใหญ่

ตั้งค่าเป็น true เพื่อให้ดำเนินการตามขั้นตอนได้อย่างต่อเนื่องแม้จะมีนโยบายแล้วก็ตาม ล้มเหลว

เท็จ ไม่บังคับ
เปิดใช้อยู่ ตั้งค่าเป็น true เพื่อบังคับใช้นโยบาย

ตั้งค่าเป็น false เป็น "ปิด" นโยบาย นโยบายนี้จะไม่บังคับใช้ แม้ว่าจะยังมีการเคลื่อนไหว

จริง ไม่บังคับ
ไม่พร้อมกัน แอตทริบิวต์นี้เลิกใช้งานแล้ว เท็จ เลิกใช้

&lt;DisplayName&gt;

<DisplayName>Policy Display Name</DisplayName>

ใช้เพิ่มเติมจากแอตทริบิวต์ชื่อเพื่อติดป้ายกำกับนโยบายในเครื่องมือแก้ไขพร็อกซี UI การจัดการ ด้วยชื่อที่เป็นภาษาธรรมชาติต่างกัน

ค่าเริ่มต้น หากคุณไม่ใส่องค์ประกอบนี้ ระบบจะใช้ค่าของแอตทริบิวต์ชื่อนโยบาย
การตรวจหาบุคคล ไม่บังคับ
ประเภท สตริง

&lt;Source&gt;

<Source>JWS-variable</Source>

หากมี ให้ระบุตัวแปรโฟลว์ที่นโยบายคาดว่าจะพบ JWS ถอดรหัส

ค่าเริ่มต้น request.header.authorization (ดูหมายเหตุด้านบนสำหรับข้อมูลสำคัญ) เกี่ยวกับค่าเริ่มต้น)
การตรวจหาบุคคล ไม่บังคับ
ประเภท สตริง
ค่าที่ถูกต้อง ชื่อตัวแปรโฟลว์ Edge

Flow variables

Upon success, the Verify JWS and Decode JWS policies set context variables according to this pattern:

jws.{policy_name}.{variable_name}

For example, if the policy name is verify-jws, then the policy will store the algorithm specified in the JWS to this context variable: jws.verify-jws.header.algorithm

Variable name Description
decoded.header.name The JSON-parsable value of a header in the payload. One variable is set for every header in the payload. While you can also use the header.name flow variables, this is the recommended variable to use to access a header.
header.algorithm The signing algorithm used on the JWS. For example, RS256, HS384, and so on. See (Algorithm) Header Parameter for more.
header.kid The Key ID, if added when the JWS was generated. See also "Using a JSON Web Key Set (JWKS)" at JWT and JWS policies overview to verify a JWS. See (Key ID) Header Parameter for more.
header.type The header type value. See (Type) Header Parameter for more.
header.name The value of the named header (standard or additional). One of these will be set for every additional header in the header portion of the JWS.
header-json The header in JSON format.
payload The JWS payload if the JWS has an attached payload. For a detached payload, this variable is empty.
valid In the case of VerifyJWS, this variable will be true when the signature is verified, and the current time is before the token expiry, and after the token notBefore value, if they are present. Otherwise false.

In the case of DecodeJWS, this variable is not set.

ข้อมูลอ้างอิงข้อผิดพลาด

This section describes the fault codes and error messages that are returned and fault variables that are set by Edge when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Occurs when
steps.jws.FailedToDecode 401 The policy was unable to decode the JWS. The JWS is possibly corrupted.
steps.jws.FailedToResolveVariable 401 Occurs when the flow variable specified in the <Source> element of the policy does not exist.
steps.jws.InvalidClaim 401 For a missing claim or claim mismatch, or a missing header or header mismatch.
steps.jws.InvalidJsonFormat 401 Invalid JSON found in the JWS header.
steps.jws.InvalidJws 401 This error occurs when the JWS signature verification fails.
steps.jws.InvalidPayload 401 The JWS payload is invalid.
steps.jws.InvalidSignature 401 <DetachedContent> is omitted and the JWS has a detached content payload.
steps.jws.MissingPayload 401 The JWS payload is missing.
steps.jws.NoAlgorithmFoundInHeader 401 Occurs when the JWS omits the algorithm header.
steps.jws.UnknownException 401 An unknown exception occurred.

Deployment errors

These errors can occur when you deploy a proxy containing this policy.

Error name Occurs when
InvalidAlgorithm The only valid values are: RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384, ES512, HS256, HS384, HS512.

EmptyElementForKeyConfiguration

FailedToResolveVariable

InvalidConfigurationForActionAndAlgorithmFamily

InvalidConfigurationForVerify

InvalidEmptyElement

InvalidFamiliesForAlgorithm

InvalidKeyConfiguration

InvalidNameForAdditionalClaim

InvalidNameForAdditionalHeader

InvalidPublicKeyId

InvalidPublicKeyValue

InvalidSecretInConfig

InvalidTypeForAdditionalClaim

InvalidTypeForAdditionalHeader

InvalidValueForElement

InvalidValueOfArrayAttribute

InvalidVariableNameForSecret

MissingConfigurationElement

MissingElementForKeyConfiguration

MissingNameForAdditionalClaim

MissingNameForAdditionalHeader

Other possible deployment errors.

ตัวแปรความผิดพลาด

ระบบจะตั้งค่าตัวแปรเหล่านี้เมื่อเกิดข้อผิดพลาดรันไทม์ โปรดดูข้อมูลเพิ่มเติมที่หัวข้อสิ่งที่คุณจำเป็นต้องทราบ เกี่ยวกับข้อผิดพลาดของนโยบาย

ตัวแปร สถานที่ ตัวอย่าง
fault.name="fault_name" fault_name คือชื่อของข้อผิดพลาดตามที่ระบุไว้ในตารางข้อผิดพลาดรันไทม์ด้านบน ชื่อข้อผิดพลาดคือส่วนสุดท้ายของรหัสข้อผิดพลาด fault.name Matches "TokenExpired"
JWS.failed นโยบาย JWS ทั้งหมดตั้งค่าตัวแปรเดียวกันในกรณีที่ดำเนินการไม่สำเร็จ jws.JWS-Policy.failed = true

ตัวอย่างการตอบสนองข้อผิดพลาด

สำหรับการจัดการข้อผิดพลาด แนวทางปฏิบัติแนะนำคือให้ดักจับส่วน errorcode ของข้อผิดพลาด คำตอบ อย่าพึ่งพาข้อความใน faultstring เนื่องจากอาจมีการเปลี่ยนแปลง

ตัวอย่างกฎข้อผิดพลาด

<FaultRules>
    <FaultRule name="JWS Policy Errors">
        <Step>
            <Name>JavaScript-1</Name>
            <Condition>(fault.name Matches "TokenExpired")</Condition>
        </Step>
        <Condition>JWS.failed=true</Condition>
    </FaultRule>
</FaultRules>